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
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
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.net2011/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
Link us to a http://gist.github.com paste please Yasou. Thanks.
It seems gmail broke newlines :(
but you'll see the idea.--
Yasuo Ohgaki
yohgaki@ohgaki.net2011/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.net2011/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
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.
It seems gmail broke newlines :(
but you'll see the idea.--
Yasuo Ohgaki
yohgaki@ohgaki.net2011/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.net2011/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