1 Aug 2012 01:23
[PHP-DEV] Traits behavior still up in the air in 5.4
Stan Vass <sv_forums <at> fmethod.com>
2012-07-31 23:23:57 GMT
2012-07-31 23:23:57 GMT
I'd like to point out some puzzling behaviors in Traits as they exist in the production releases of PHP 5.4.
----------------------------------------------------------------------------
1. Name collisions between a trait method and a class method using the trait go unreported, the class
silently shadowing the trait method:
----------------------------------------------------------------------------
trait T {
function foo() { $this->bar; }
function bar() { echo 'trait'; }
}
class C {
use T;
function bar() { echo 'class'; }
}
$c = new C;
$c->foo(); // "class"
Proposed behavior: Fatal error on collision, unless the method is imported with a unique name using the {
... as ... } syntax.
----------------------------------------------------------------------------
2. Using "as" syntax when importing a trait does NOT rename a method, but creates an alias CLONE, the
original method still callable.
----------------------------------------------------------------------------
trait T {
function bar() { echo 'trait'; }
(Continue reading)
RSS Feed