Re: 5.4a2 trait attribute name conflict resolution

From: Date: Fri, 22 Jul 2011 15:40:51 +0000
Subject: Re: 5.4a2 trait attribute name conflict resolution
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-54131@lists.php.net to get a copy of this message
On 22 July 2011 16:17, Alex Howansky <alex.howansky@gmail.com> wrote: > > Hello folks, > > I've just grabbed 5.4a2 to play with traits. I've found some behaviour which > I'm not sure is a bug, an inconsistency, or a design decision. > > Consider a trait and a class that implements it but also overrides both a > trait method and a trait attribute: > > 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 traits RFC pretty clearly states that if a class method conflicts with a > trait method then the trait method will be ignored, which is what's > happening, but it says nothing about what happens to attributes in that same > condition. Is this a bug? > > Thanks, > > -- > Alex Howansky > > In my limited understanding, a trait is sort of composited at compile time (ish). As properties are dynamic (ish), they will overwrite. Just like an inherited class will overwrite public properties in their parent class. -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

« previous php.internals (#54131) next »