RE: [PHP-DEV] 5.4a2 trait attribute name conflict resolution

From: Date: Fri, 22 Jul 2011 17:01:18 +0000
Subject: RE: [PHP-DEV] 5.4a2 trait attribute name conflict resolution
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-54144@lists.php.net to get a copy of this message
On Fri Jul 22 11:17 AM, Alex Howansky wrote: > trait foo > { > public $zoo = 'foo::zoo'; > public function bar() > { > echo "in foo::bar\n"; > } > } > > class baz > { > use foo; > public $zoo = 'baz::zoo'; > public function bar() > { > echo "in baz::bar\n"; > } > } > > $obj = new baz(); > $obj->bar(); > echo $obj->zoo, "\n"; > > We get: > > in baz::bar > foo::zoo > > It seems this is not correct and that it should be: > > in baz::bar > baz::zoo > The expected behavior is an E_STRICT notice: http://svn.php.net/viewvc/php/php-src/trunk/Zend/tests/traits/property001.ph pt?view=markup&pathrev=306476 If the modifier is different/conflicting (public, protected, private) E_FATAL http://svn.php.net/viewvc?view=revision&revision=306476 http://marc.info/?l=php-internals&m=129251322332367&w=2 The theory is traits should not have conflicting state/properties. Best practice, always choose trait property names carefully/~unique so that you don't run into conflicts. The short answer is it's not a bug but maybe an implementation issue... should it be an E_WARNING instead of E_STRICT?

« previous php.internals (#54144) next »