com php-src: Fixed bug #64235 (Insteadof not work for class method in 5.4.11): NEWS Zend/tests/traits/bug64235.phpt Zend/tests/traits/bug64235b.phpt
Zend/tests/traits/language015.phpt Zend/tests/traits/language016.phpt Zend/tests/traits/language017.phpt Zend/zend_compile.c
| From: | Xinchen Hui | Date: | Thu, 21 Feb 2013 10:18:41 +0000 |
| Subject: | com php-src: Fixed bug #64235 (Insteadof not work for class method in 5.4.11): NEWS Zend/tests/traits/bug64235.phpt Zend/tests/traits/bug64235b.phpt Zend/tests/traits/language015.phpt Zend/tests/traits/language016.phpt Zend/tests/traits/language017.phpt Zend/zend_compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-71276@lists.php.net to get a copy of this message | ||
Commit: 9a44a9806c7c7a8c1fc691210335d0691a4597be
Author: Xinchen Hui <laruence@php.net> Thu, 21 Feb 2013 18:18:41 +0800
Parents: bae95bd9d4e11e3362926e6fee0638336d9adf62
Branches: PHP-5.4
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9a44a9806c7c7a8c1fc691210335d0691a4597be
Log:
Fixed bug #64235 (Insteadof not work for class method in 5.4.11)
As we discussed with stefan, we think previous of allowing use with
classes is a bug, should be forbided, anyway, the error message should
be improved.
Bugs:
https://bugs.php.net/64235
Changed paths:
M NEWS
A Zend/tests/traits/bug64235.phpt
A Zend/tests/traits/bug64235b.phpt
M Zend/tests/traits/language015.phpt
M Zend/tests/traits/language016.phpt
M Zend/tests/traits/language017.phpt
M Zend/zend_compile.c
Diff:
diff --git a/NEWS b/NEWS
index e34b0c5..c9cc2b5 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PHP NEWS
?? ??? 2012, PHP 5.4.13
- Core:
+ . Fixed bug #64235 (Insteadof not work for class method in 5.4.11).
+ (Laruence)
. Implemented FR #64175 (Added HTTP codes as of RFC 6585). (Jonh Wendell)
. Fixed bug #64142 (dval to lval different behavior on ppc64). (Remi)
. Fixed bug #64070 (Inheritance with Traits failed with error). (Dmitry)
diff --git a/Zend/tests/traits/bug64235.phpt b/Zend/tests/traits/bug64235.phpt
new file mode 100644
index 0000000..d0a2a98
--- /dev/null
+++ b/Zend/tests/traits/bug64235.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #64235 (Insteadof not work for class method in 5.4.11)
+--FILE--
+<?php
+
+class TestParentClass
+{
+ public function method()
+ {
+ print_r('Parent method');
+ print "\n";
+ }
+}
+
+trait TestTrait
+{
+ public function method()
+ {
+ print_r('Trait method');
+ print "\n";
+ }
+}
+
+class TestChildClass extends TestParentClass
+{
+ use TestTrait
+ {
+ TestTrait::method as methodAlias;
+ TestParentClass::method insteadof TestTrait;
+ }
+}
+?>
+--EXPECTF--
+Fatal error: Class TestParentClass is not a trait, Only traits may be used in 'as' and
'insteadof' statements in %sbug64235.php on line %d
diff --git a/Zend/tests/traits/bug64235b.phpt b/Zend/tests/traits/bug64235b.phpt
new file mode 100644
index 0000000..a326ec0
--- /dev/null
+++ b/Zend/tests/traits/bug64235b.phpt
@@ -0,0 +1,35 @@
+--TEST--
+Bug #64235 (Insteadof not work for class method in 5.4.11)
+--FILE--
+<?php
+
+class TestParentClass
+{
+ public function method()
+ {
+ print_r('Parent method');
+ print "\n";
+ }
+}
+
+trait TestTrait
+{
+ public function method()
+ {
+ print_r('Trait method');
+ print "\n";
+ }
+}
+
+class TestChildClass extends TestParentClass
+{
+ use TestTrait
+ {
+ TestTrait::method as methodAlias;
+ TestParentClass::method as TestParent;
+ }
+}
+
+?>
+--EXPECTF--
+Fatal error: Class TestParentClass is not a trait, Only traits may be used in 'as' and
'insteadof' statements in %sbug64235b.php on line %d
diff --git a/Zend/tests/traits/language015.phpt b/Zend/tests/traits/language015.phpt
index df1f744..0c9fb4a 100644
--- a/Zend/tests/traits/language015.phpt
+++ b/Zend/tests/traits/language015.phpt
@@ -14,4 +14,4 @@ class C {
}
}
--EXPECTF--
-Fatal error: Trait T2 is not used in %s on line %d
+Fatal error: Required Trait T2 wasn't added to C in %slanguage015.php on line %d
diff --git a/Zend/tests/traits/language016.phpt b/Zend/tests/traits/language016.phpt
index e928119..1c6bbea 100644
--- a/Zend/tests/traits/language016.phpt
+++ b/Zend/tests/traits/language016.phpt
@@ -14,4 +14,4 @@ class C {
}
}
--EXPECTF--
-Fatal error: Trait T2 is not used in %s on line %d
+Fatal error: Required Trait T2 wasn't added to C in %slanguage016.php on line %d
diff --git a/Zend/tests/traits/language017.phpt b/Zend/tests/traits/language017.phpt
index 56f9e24..539a05d 100644
--- a/Zend/tests/traits/language017.phpt
+++ b/Zend/tests/traits/language017.phpt
@@ -14,4 +14,4 @@ class C {
}
}
--EXPECTF--
-Fatal error: Trait T2 is not used in %s on line %d
+Fatal error: Required Trait T2 wasn't added to C in %slanguage017.php on line %d
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index a3f4fe5..0a1749d 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3859,12 +3859,16 @@ static void zend_check_trait_usage(zend_class_entry *ce, zend_class_entry
*trait
{
zend_uint i;
+ if ((trait->ce_flags & ZEND_ACC_TRAIT) != ZEND_ACC_TRAIT) {
+ zend_error(E_COMPILE_ERROR, "Class %s is not a trait, Only traits may be used in
'as' and 'insteadof' statements", trait->name);
+ }
+
for (i = 0; i < ce->num_traits; i++) {
if (ce->traits[i] == trait) {
return;
}
}
- zend_error(E_COMPILE_ERROR, "Trait %s is not used", trait->name);
+ zend_error(E_COMPILE_ERROR, "Required Trait %s wasn't added to %s", trait->name,
ce->name);
}
/* }}} */