Re: Class Properties in Interfaces?
| From: | Lars Strojny | Date: | Tue, 06 May 2008 20:04:29 +0000 |
| Subject: | Re: Class Properties in Interfaces? | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37505@lists.php.net to get a copy of this message | ||
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
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc