Re: Getters/Setters and parent getter/setter access
| From: | Yasuo Ohgaki | Date: | Sun, 20 Nov 2011 00:26:03 +0000 |
| Subject: | Re: Getters/Setters and parent getter/setter access | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-56440@lists.php.net to get a copy of this message | ||
Sure. I did.
https://gist.github.com/1379592
--
Yasuo Ohgaki
yohgaki@ohgaki.net
2011/11/20 Paul Dragoonis <dragoonis@gmail.com>:
> Link us to a http://gist.github.com paste please Yasou. Thanks.
>
> On Sat, Nov 19, 2011 at 9:45 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
>> It seems gmail broke newlines :(
>> but you'll see the idea.
>>
>> --
>> Yasuo Ohgaki
>> yohgaki@ohgaki.net
>>
>>
>>
>> 2011/11/20 Yasuo Ohgaki <yohgaki@ohgaki.net>:
>>> This is not a alternate syntax suggestion, but a currently working
>>> solution (well partial)
>>>
>>> <?phptrait Accessors{ public function __get($name) { if
>>> ($this->r_property[$name]) return $this->$name; else
>>> trigger_error("Access to read protected property");}
>>> public function __set($name, $value) { if ($this->w_property[$name])
>>> $this->$name = $value; else trigger_error("Access to write
>>> protected property");}}
>>> class OrderLine{ use Accessors;
>>> private $r_property = array('price'=>1, 'amount'=>1);
>>> private
>>> $w_property = array('price'=>1, 'amount'=>1);
>>> protected $price; private $amount;
>>> public function getTotal() { return $this->price * $this->amount; }}
>>> $line = new OrderLine;
>>> $line->price = 20;$line->amount = 3;
>>> echo "Total cost: ".$line->getTotal();?>
>>>
>>> You might would like to add as a current solution.
>>>
>>> --
>>> Yasuo Ohgaki
>>> yohgaki@ohgaki.net
>>>
>>>
>>>
>>> 2011/11/19 Clint M Priest <cpriest@zerocue.com>:
>>>> The RFC here:
>>>> https://wiki.php.net/rfc/propertygetsetsyntax
>>>>
>>>> Talks about allowing a sub-class to access a parent getter via
>>>> TimePeriod::$Milliseconds or possibly parent::$Milliseconds.
>>>>
>>>> Either of those methods (currently) tries to access a static property in the parent
>>>> or defined class. It would probably break existing code if we tried to make the parent:: or
>>>> TimePeriod:: syntax to access the parent accessor.
>>>>
>>>> Anyone have any suggestions on an alternative syntax?
>>>>
>>>> I'm sure I could change it so that parent:: or TimePeriod:: from within a
>>>> getter/setter would cause it to access the parent getter/setter but that would create an
>>>> inconsistency within the language.
>>>>
>>>> Ideas?
>>>>
>>>> -Clint
>>>>
>>>
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>