Hi Benjamin, > I have been working with Objective-c lately, and it has a very flexible > and short way to deal with properties, which could look like this in PHP : > > <?php > class TimePeriod { > protected $seconds; > protected $minutes; > protected $hours; > > > @synthesize (readwrite) $hours, $minutes; > @synthesize (readonly) $seconds; > } > > NB : I intentionally skipped the @property declaration wich I believe is a > specific need for objc (used to allow dot syntax usage). > > > In objc, this notation allows to : > > - use dot syntax for accessing properties (using their getters/setters > only, all properties are protected in objc) > - write your own getters/setters (only the missing ones are generated) > > > In Php, the pros of this syntax would be : > > - very concise > - no interference with existing code (except certain conditions) > - allows to override generated getters and setters with custom code > - may work with the existing code base > > The cons : > > - new syntax to learn (even if it is quite simple) > - need to use pre-determined setters and getters names to keep simplicity, > which could potentially lead to BC break in some (hopefully rare) cases. > > > What do you think about it ?
The issue I have with this syntax is it does not look similar to any other syntax in PHP (that I know of). It looks out of place. Additionally, I believe the readonly and writeonly keywords are slated to have other meanings (as noted in my RFC), and this would cause confusion. Also, if a property is defined "readonly", when we inherit the class, how do we now define the write method? I don't see any logical or coherent way with this syntax. Lastly, your syntax misses the point of properties. The point is not to put an alias on an existing variable, or even to read and write to different variables. The real power is that the get and set are methods! For example, in the "get" method, I could make a soap call to another server, load in a result document and get my value from there. In a set method, I could make a database call and store the value. These are extreme scenarios, but they show the power of properties. - Dennis -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php