Doc #62936 [Opn]: Last Trait wins on importing conflicting properties

From: Date: Sun, 26 Aug 2012 16:26:57 +0000
Subject: Doc #62936 [Opn]: Last Trait wins on importing conflicting properties
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8770@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62936&edit=1 ID: 62936 User updated by: r dot wilczek at web-appz dot de Reported by: r dot wilczek at web-appz dot de -Summary: Trait-Properties overwrite properties in the importing scope +Summary: Last Trait wins on importing conflicting properties Status: Open Type: Documentation Problem Package: Documentation problem PHP Version: 5.4.6 Block user comment: N Private report: N New Comment: Actually, the docblock is taken from the last trait listed in the use-statement: class Foo { use TraitA, TraitB; private $foo; } If TraitB provides private $foo, the docblock will be taken from TraitB, discarding any private $foo defined in TraitA or class Foo. class Foo { use Trait, TraitA; private $foo; } Now the docblock is taken from TraitA. Previous Comments: ------------------------------------------------------------------------ [2012-08-26 16:02:04] r dot wilczek at web-appz dot de Description: ------------ In addition to the PHP manual stating ... If a trait defines a property then a class can not define a property with the same name, otherwise an error is issued. It is an E_STRICT if the class definition is compatible (same visibility and initial value) or fatal error otherwise ... note, that if you ignore the E_STRICT-notice, PHP will fetch the docblock of the imported property, discarding the docblock of conflicting property in the importing module. Test script: --------------- error_reporting(E_ALL ^ E_STRICT); trait MyTrait { /** * Comes from trait */ private $foo; } class MyClass { use MyTrait; /** * Comes from class */ private $foo; } $classFoo = new \ReflectionProperty('MyClass', 'foo'); $traitFoo = new \ReflectionProperty('MyTrait', 'foo'); var_export($traitFoo->getDocComment() == $classFoo->getDocComment()); Expected result: ---------------- true // if the composed class contains the docblock of MyTrait::$foo false // if the composed class contains the docblock of MyClass::$foo Actual result: -------------- true ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62936&edit=1

« previous php.doc.bugs (#8770) next »