2008/5/6 Lars Strojny <[EMAIL PROTECTED]>: > Hi Marcus! > > Am Dienstag, den 06.05.2008, 21:45 +0200 schrieb Marcus Boerger: > [...] > > > All fine with me. However we *would* need to specify which function is > > getter, setter, isset or unset. > > [...] > > > > > public $property { > > string public function __get() { > > return $this->_property; > > } > > string protected function __set(string $value) {...} > > } > > That's the variant I prefer. It is pretty similar to the C# does it and > therefore follows the common PHP strategy of steeling everything > together ;) > > [...] > > > The advantage of keeping everything inside the property definition is that > > there is no need at all for any new keyword. And the handlers cannot get > > separated. The disadvantage is that the functions are always named __get > and > > so on for all properties, so PHP would need to do an internal renaming. > > Which means we probably would not be able to call the functions manually. > > Do you see any real use-case for calling them directly? > > > > That larger handlers could clutter the code doesn't appear to be a > > disadvantage for me as it can easily be avoided if the handler just > > forwards the call. > > Either that or folding in the editor helps etc. pp. > > > > The next question I have now is what to do when people want direct access > > to the underlying value? > > I would think that accessing $this->property from __get()/__set() of the > property would address the value itself. Everything else would be > redirected to the accessors. > > > > Or do we force people to always specify get,set,isset und unset? Or > > should we only enforce get/set and have isset > > and unset emulated with them (isset()~>isset(get()), > > unset()~>set(NULL))? > > Not sure about that. Forcing the user to define four accessors for a > property seems to be clutter but it would be - technically spoken - > correct. I don't have a fixed opinion here. > > cu, Lars >
You would only normally need to define the four accessors if your property isn't a bog standard one or you didn't want to trigger any activity when a property changed. class foo { public $bar; } is fine. foo::bar is a completely normal property as we know it. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php