summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2007-12-03 14:15:43 +0000
committerDmitry Stogov <dmitry@php.net>2007-12-03 14:15:43 +0000
commit0f59a01e4a564959866e7e0a821de55bca05a209 (patch)
treee9ffa188acdd8210ace1146a622fb54f3b5c2658 /Zend
parent7192e8af1531a1ed5568c415b75796f626a7abb2 (diff)
downloadphp-git-0f59a01e4a564959866e7e0a821de55bca05a209.tar.gz
Fixed bug #43332 (self and parent as type hint in namespace)
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/bug43332_1.phpt15
-rw-r--r--Zend/tests/bug43332_2.phpt15
-rw-r--r--Zend/zend_compile.c8
3 files changed, 37 insertions, 1 deletions
diff --git a/Zend/tests/bug43332_1.phpt b/Zend/tests/bug43332_1.phpt
new file mode 100644
index 0000000000..ef32162100
--- /dev/null
+++ b/Zend/tests/bug43332_1.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #43332.1 (self and parent as type hint in namespace)
+--FILE--
+<?php
+namespace foobar;
+
+class foo {
+ public function bar(self $a) { }
+}
+
+$foo = new foo;
+$foo->bar($foo); // Ok!
+$foo->bar(new stdclass); // Error, ok!
+--EXPECTF--
+Catchable fatal error: Argument 1 passed to foobar::foo::bar() must be an instance of foobar::foo, instance of stdClass given, called in %sbug43332_1.php on line 10 and defined in %sbug43332_1.php on line 5
diff --git a/Zend/tests/bug43332_2.phpt b/Zend/tests/bug43332_2.phpt
new file mode 100644
index 0000000000..916f6fa354
--- /dev/null
+++ b/Zend/tests/bug43332_2.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #43332.2 (self and parent as type hint in namespace)
+--FILE--
+<?php
+namespace foobar;
+
+class foo {
+ public function bar(::self $a) { }
+}
+
+$foo = new foo;
+$foo->bar($foo); // Ok!
+$foo->bar(new stdclass); // Error, ok!
+--EXPECTF--
+Fatal error: '::self' is a wrong class name in %sbug43332_2.php on line 5
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index bdb51ef121..3c3b4cf7f9 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1342,7 +1342,9 @@ void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initia
if (class_type->op_type != IS_UNUSED) {
cur_arg_info->allow_null = 0;
if (class_type->u.constant.type == IS_STRING) {
- zend_resolve_class_name(class_type, &opline->extended_value, 1 TSRMLS_CC);
+ if (ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_STRVAL(class_type->u.constant), Z_STRLEN(class_type->u.constant))) {
+ zend_resolve_class_name(class_type, &opline->extended_value, 1 TSRMLS_CC);
+ }
cur_arg_info->class_name = class_type->u.constant.value.str.val;
cur_arg_info->class_name_len = class_type->u.constant.value.str.len;
if (op == ZEND_RECV_INIT) {
@@ -1542,6 +1544,10 @@ void zend_resolve_class_name(znode *class_name, ulong *fetch_type, int check_ns_
Z_STRVAL(class_name->u.constant) = erealloc(
Z_STRVAL(class_name->u.constant),
Z_STRLEN(class_name->u.constant) + 1);
+
+ if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant))) {
+ zend_error(E_COMPILE_ERROR, "'::%s' is a wrong class name", Z_STRVAL(class_name->u.constant));
+ }
} else if (CG(current_import)) {
len = compound - Z_STRVAL(class_name->u.constant);
lcname = zend_str_tolower_dup(Z_STRVAL(class_name->u.constant), len);