cvs: ZendEngine2 / zend_compile.c /tests bug43332_1.phpt bug43332_2.phpt
| From: | Dmitry Stogov | Date: | Mon, 03 Dec 2007 14:15:55 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c /tests bug43332_1.phpt bug43332_2.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-6217@lists.php.net to get a copy of this message | ||
dmitry Mon Dec 3 14:15:55 2007 UTC
Modified files:
/ZendEngine2 zend_compile.c
/ZendEngine2/tests bug43332_1.phpt bug43332_2.phpt
Log:
Fixed bug #43332 (self and parent as type hint in namespace)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.787&r2=1.788&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.787 ZendEngine2/zend_compile.c:1.788
--- ZendEngine2/zend_compile.c:1.787 Thu Nov 22 10:46:44 2007
+++ ZendEngine2/zend_compile.c Mon Dec 3 14:15:55 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.787 2007/11/22 10:46:44 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.788 2007/12/03 14:15:55 dmitry Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -1436,7 +1436,9 @@
if (class_type->op_type != IS_UNUSED) {
cur_arg_info->allow_null = 0;
if (Z_TYPE(class_type->u.constant) == IS_STRING || Z_TYPE(class_type->u.constant) ==
IS_UNICODE) {
- zend_resolve_class_name(class_type, &opline->extended_value, 1 TSRMLS_CC);
+ if (ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(Z_TYPE(class_type->u.constant),
Z_UNIVAL(class_type->u.constant), Z_UNILEN(class_type->u.constant))) {
+ zend_resolve_class_name(class_type, &opline->extended_value, 1 TSRMLS_CC);
+ }
cur_arg_info->class_name = Z_UNIVAL(class_type->u.constant);
cur_arg_info->class_name_len = Z_UNILEN(class_type->u.constant);
if (op == ZEND_RECV_INIT) {
@@ -1665,6 +1667,9 @@
Z_USTRVAL(class_name->u.constant) = eurealloc(
Z_USTRVAL(class_name->u.constant),
Z_USTRLEN(class_name->u.constant) + 1);
+ if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(Z_TYPE(class_name->u.constant),
Z_UNIVAL(class_name->u.constant), Z_UNILEN(class_name->u.constant))) {
+ zend_error(E_COMPILE_ERROR, "'::%R' is a wrong class name",
Z_TYPE(class_name->u.constant), Z_UNIVAL(class_name->u.constant));
+ }
} else if (Z_TYPE(class_name->u.constant) == IS_STRING &&
Z_STRVAL(class_name->u.constant)[0] == ':') {
/* The STRING name has "::" prefix */
@@ -1673,6 +1678,9 @@
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_TYPE(class_name->u.constant),
Z_UNIVAL(class_name->u.constant), Z_UNILEN(class_name->u.constant))) {
+ zend_error(E_COMPILE_ERROR, "'::%R' is a wrong class name",
Z_TYPE(class_name->u.constant), Z_UNIVAL(class_name->u.constant));
+ }
} else if (CG(current_import)) {
if (Z_TYPE(class_name->u.constant) == IS_UNICODE) {
len = compound.u - Z_USTRVAL(class_name->u.constant);
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug43332_1.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug43332_1.phpt
diff -u /dev/null ZendEngine2/tests/bug43332_1.phpt:1.2
--- /dev/null Mon Dec 3 14:15:55 2007
+++ ZendEngine2/tests/bug43332_1.phpt Mon Dec 3 14:15:55 2007
@@ -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
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug43332_2.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug43332_2.phpt
diff -u /dev/null ZendEngine2/tests/bug43332_2.phpt:1.2
--- /dev/null Mon Dec 3 14:15:55 2007
+++ ZendEngine2/tests/bug43332_2.phpt Mon Dec 3 14:15:55 2007
@@ -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