Electronics & Programming


Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 11, 2010 16:47:53

Stefan M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Traits and Properties


Traits do not provide any special provisioning for handling properties,
especially, there is no language solution for handling colliding property names.
The current solution/idiom for handling state safely in a trait is to use
either abstract set/get methods or an abstract get that returns a reference to
the property in the class.

However, at the moment it is possible to define properties in a trait:

trait Foo {
private $a;
public $foo;

For the moment, that information is completely ignored, thus:

class Bar {
use Foo;
property_exists('Bar', 'a') === false

Well, and that is a rather inconsistent status-quo.

I would like to have that fixed in one or another way.

One possibility would be to forbid property definition in a trait altogether.
That reduces a bit the possibility to have wrong expectations about properties,
however, the dynamic property creation is still possible.

Another way would be to merge the properties in the composing class.
The question here would be how to treat visibility modifiers: how to merge
public and private, should it result in public, or private?
And, to discorage users to go this way, should there be a STRICT notice?
Options here are a notice whenever a property is defined in a trait, or
whenever properties are silently merged.

Comments very welcome.


Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgiumhttp://soft.vub.ac.be/~smarrPhone: +32 2 629 2974
Fax: +32 2 629 3525

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


Board footer

Moderator control

Enjoy the 21st of January

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support