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
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
