| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2012-08-26 16:02 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 13:00:02 2025 UTC | 
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.This seems to be related, and appears to show some sort of inconsistency. FreeBSD www 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #3: root@www:/usr/obj/usr/src/sys/XENHVM amd64 PHP 5.4.6 (cli) (built: Sep 11 2012 09:19:59) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies CODE: --------- $classFoo = new \ReflectionProperty('MyClass','foo'); $traitFoo = new \ReflectionProperty('MyTrait','foo'); echo $traitFoo->getDeclaringClass()->getName().PHP_EOL; echo $traitFoo->getDocComment().PHP_EOL; echo $classFoo->getDeclaringClass()->getName().PHP_EOL; echo $classFoo->getDocComment().PHP_EOL; OUTPUT: -------- MyTrait /** * Comes from trait */ MyClass /** * Comes from trait */