On 11 December 2010 23:31, Stefan Marr <p...@stefan-marr.de> wrote:
> The current status of the property behavior is not yet documented explicitly

On the assumption that traits WILL include properties (with
visibility) and aliasing can do all its magic, how would the situation
be handled where multiple traits define shared properties.

I've not got a use case, but say trait1 and trait2 both define the
same property.

Assuming name conflicts are handled via aliasing, then the property
needs to alert the aliasing code that this property is a non
conflicting property. All traits wanting to access the shared property
would have to reveal their intentions.

I can think of 2 ways to handle this (but I'm no genius here, so take
them apart at your pleasure).

1 - The trait's code marks shared properties with a keyword (shared,
common, virtual, something). During incorporation of the trait into
the main class, any marked properties are checked for visibility only.
2 - The trait's code uses a &$property. The fact that this is a
reference would require the creation of the property (if it doesn't
already exist) whilst the trait is being compiled into the main class.
I'd guess this would be the least difficult to implement, but I know
squat about this.

I'm guessing the order of handling the traits would be significant here.

Trait1 uses $property, Trait2 uses $property - conflict. Must be
resolved by aliasing or an error.
Trait1 uses &$property, Trait2 uses &$property - all ok. Trait1 wants
access a non existing property, so one is created. Trait2 is sharing
the now pre-existing property.
Trait1 uses &$property, Trait2 uses $property - conflict. Trait1 wants
access a non existing property, so one is created. Trait2's $property
must be aliased to an error.
Trait1 uses $property, Trait2 uses &$property - all ok. Trait1's
$property is added as expected. Trait2 is sharing the now pre-existing
property.

Richard.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to