svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/tests/traits/bug61052.phpt branches/PHP_5_4/Zend/zend_compile.c
trunk/Zend/tests/traits/bug61052.phpt trunk/Zend/zend_compile.c
| From: | Stefan Marr | Date: | Sun, 04 Mar 2012 19:34:19 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/tests/traits/bug61052.phpt branches/PHP_5_4/Zend/zend_compile.c trunk/Zend/tests/traits/bug61052.phpt trunk/Zend/zend_compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-67827@lists.php.net to get a copy of this message | ||
gron Sun, 04 Mar 2012 19:34:19 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=323898
Log:
Fixed Bug #61052 (Missing error check in trait 'insteadof' clause)
Bug: https://bugs.php.net/61052 (Assigned) missing error
check in trait 'insteadof' clause
Changed paths:
U php/php-src/branches/PHP_5_4/NEWS
A php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt
U php/php-src/branches/PHP_5_4/Zend/zend_compile.c
A php/php-src/trunk/Zend/tests/traits/bug61052.phpt
U php/php-src/trunk/Zend/zend_compile.c
Modified: php/php-src/branches/PHP_5_4/NEWS
===================================================================
--- php/php-src/branches/PHP_5_4/NEWS 2012-03-04 19:30:01 UTC (rev 323897)
+++ php/php-src/branches/PHP_5_4/NEWS 2012-03-04 19:34:19 UTC (rev 323898)
@@ -23,6 +23,7 @@
vars). (Laruence)
. Fixed bug #61011 (Crash when an exception is thrown by __autoload
accessing a static property). (Laruence)
+ . Fixed bug #61052 (Missing error check in trait 'insteadof' clause). (Stefan)
. Fixed bug #61072 (Memory leak when restoring an exception handler).
(Nikic, Laruence)
. Fixed bug #61087 (Memory leak in parse_ini_file when specifying
Added: php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt (rev 0)
+++ php/php-src/branches/PHP_5_4/Zend/tests/traits/bug61052.phpt 2012-03-04 19:34:19 UTC (rev
323898)
@@ -0,0 +1,18 @@
+--TEST--
+Bug #61052 (missing error check in trait 'insteadof' clause)
+--FILE--
+<?php
+trait T1 {
+ function foo(){ echo "T1\n"; }
+}
+trait T2 {
+ function foo(){ echo "T2\n"; }
+}
+class C {
+ use T1, T2 {
+ T1::foo insteadof T1;
+ }
+}
+C::foo();
+--EXPECTF--
+Fatal error: Inconsistent insteadof definition. The method foo is to be used from T1, but T1 is
also on the exclude list in %s on line %d
Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c
===================================================================
--- php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2012-03-04 19:30:01 UTC (rev 323897)
+++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c 2012-03-04 19:34:19 UTC (rev 323898)
@@ -3984,13 +3984,28 @@
/** With the other traits, we are more permissive.
We do not give errors for those. This allows to be more
- defensive in such definitions. */
+ defensive in such definitions.
+ However, we want to make sure that the insteadof declartion
+ is consistent in itself.
+ */
j = 0;
while (cur_precedence->exclude_from_classes[j]) {
char* class_name = (char*)cur_precedence->exclude_from_classes[j];
zend_uint name_length = strlen(class_name);
cur_precedence->exclude_from_classes[j] = zend_fetch_class(class_name, name_length,
ZEND_FETCH_CLASS_TRAIT TSRMLS_CC);
+
+ /* make sure that the trait method is not from a class mentioned in
+ exclude_from_classes, for consistency */
+ if (cur_precedence->trait_method->ce == cur_precedence->exclude_from_classes[i]) {
+ zend_error(E_COMPILE_ERROR,
+ "Inconsistent insteadof definition. "
+ "The method %s is to be used from %s, but %s is also on the exclude list",
+ cur_method_ref->method_name,
+ cur_precedence->trait_method->ce->name,
+ cur_precedence->trait_method->ce->name);
+ }
+
efree(class_name);
j++;
}
Added: php/php-src/trunk/Zend/tests/traits/bug61052.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bug61052.phpt (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bug61052.phpt 2012-03-04 19:34:19 UTC (rev 323898)
@@ -0,0 +1,18 @@
+--TEST--
+Bug #61052 (missing error check in trait 'insteadof' clause)
+--FILE--
+<?php
+trait T1 {
+ function foo(){ echo "T1\n"; }
+}
+trait T2 {
+ function foo(){ echo "T2\n"; }
+}
+class C {
+ use T1, T2 {
+ T1::foo insteadof T1;
+ }
+}
+C::foo();
+--EXPECTF--
+Fatal error: Inconsistent insteadof definition. The method foo is to be used from T1, but T1 is
also on the exclude list in %s on line %d
Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c 2012-03-04 19:30:01 UTC (rev 323897)
+++ php/php-src/trunk/Zend/zend_compile.c 2012-03-04 19:34:19 UTC (rev 323898)
@@ -3984,13 +3984,28 @@
/** With the other traits, we are more permissive.
We do not give errors for those. This allows to be more
- defensive in such definitions. */
+ defensive in such definitions.
+ However, we want to make sure that the insteadof declartion
+ is consistent in itself.
+ */
j = 0;
while (cur_precedence->exclude_from_classes[j]) {
char* class_name = (char*)cur_precedence->exclude_from_classes[j];
zend_uint name_length = strlen(class_name);
cur_precedence->exclude_from_classes[j] = zend_fetch_class(class_name, name_length,
ZEND_FETCH_CLASS_TRAIT TSRMLS_CC);
+
+ /* make sure that the trait method is not from a class mentioned in
+ exclude_from_classes, for consistency */
+ if (cur_precedence->trait_method->ce == cur_precedence->exclude_from_classes[i]) {
+ zend_error(E_COMPILE_ERROR,
+ "Inconsistent insteadof definition. "
+ "The method %s is to be used from %s, but %s is also on the exclude list",
+ cur_method_ref->method_name,
+ cur_precedence->trait_method->ce->name,
+ cur_precedence->trait_method->ce->name);
+ }
+
efree(class_name);
j++;
}