RE: [PHP-DEV] Extensions to traits
| From: | Jonathan Bond-Caron | Date: | Tue, 15 Feb 2011 15:02:48 +0000 |
| Subject: | RE: [PHP-DEV] Extensions to traits | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51450@lists.php.net to get a copy of this message | ||
On Thu Feb 10 12:25 PM, Ben Schmidt wrote:
>
> http://wiki.php.net/rfc/traitsmodifications
>
Some thoughts:
a) Class method conflict with trait
Class implementation always wins I feel is the right way to think about
traits.
But 'abstract' already has special meaning, so maybe a keyword like 'final'
could also do something special.
b) Support for 'non-breakable traits'
- Add trait-local scope
Really like the idea and how this could make traits less fragile.
e.g.
trait Foo {
trait $bar;
public $bar;
}
Could change the syntax to:
trait Foo {
var $bar = 'visibleByTrait'; // variable private to the trait --
zend_mangle_property_name('#Foo {NULL} bar')
public $bar = 'visibleByClass'; // variable public to the class it gets
composed in
}
class Test {
use Foo;
}
$t = new Test;
echo $t->bar; // 'visibleByClass'
Seems like it could allow traits to have their own independent state
(private properties), internally ~ zend_mangle_property_name('#' trait name
{NULL} prop name).
Small note: is there a plan to drop the T_VAR token?
Any objections, concerns, more thoughts on the concept?
c) Extend 'use' syntax
Didn't quite understand, will read again.
Have you thought about how this could affect the reflection api and
documentation?