RE: [PHP-DEV] horizontal reuse: traits vs. grafts

From: Date: Wed, 24 Mar 2010 16:58:26 +0000
Subject: RE: [PHP-DEV] horizontal reuse: traits vs. grafts
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-47569@lists.php.net to get a copy of this message
On Wed Mar 24 06:50 AM, Lukas Kahwe Smith wrote: > Ahoi, > > Thought it would be better to open up a new thread and also using the > term "horizontal reuse" in the subject so that we make it clearer that > there are actually two approaches. Here is the URL for Stefan's > proposal: > http://wiki.php.net/rfc/horizontalreuse > One thing I feel is missing from the RFC is how is_a() and instanceof are affected with traits or grafts. From: http://github.com/gron/php-src/blob/PHP_5_3-traits/Zend/tests/traits/languag e009.phpt class Foo { use C, A, B { B::foo instead A, C; } } $f = new Foo; echo is_a($f, 'A'); ? echo is_a($f, 'B'); ? It's seem to me that a defining a 'trait' should be advertised strictly as an 'advanced multiple inheritance technique' to reuse pieces of code and it shouldn't be considered as an object (grafts proposal). I don't like the "B::foo instead A, C" stuff though, so I agree with Lukas and find that Grafts are more intuitive / easy to learn. Personally, this syntax makes me happy but would keep the 'use' or 'with' keyword: http://wiki.php.net/rfc/nonbreakabletraits trait A { protected function foo() { echo 'a'; } } trait D { public function foo() { echo "d"; } function bar() { echo "d"; } } class Foo { use A; use D { function bar(); } } $f = new Foo; echo is_a($f, 'A'); // true echo is_a($f, 'D'); // false, since we've done an explicit selection/brackets: use D {} This is mainly userland feedback

« previous php.internals (#47569) next »