note 105176 modified in language.oop5.overloading by danbrown

From: Date: Mon, 01 Aug 2011 16:25:24 +0000
Subject: note 105176 modified in language.oop5.overloading by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182074@lists.php.net to get a copy of this message
Since this was getting me for a little bit, I figure I better pipe in here... For nested calls to private/protected variables(probably functions too) what it does is call a __get() on the first object, and if you return the nested object, it then calls a __get() on the nested object because, well it is protected as well. EG: <?php class A { protected $B public function __construct() { $this->B = new B(); } public function __get($variable) { echo "Class A::Variable " . $variable . "\n\r"; $retval = $this->{$variable}; return $retval; } } class B { protected $val public function __construct() { $this->val = 1; } public function __get($variable) { echo "Class B::Variable " . $variable . "\n\r"; $retval = $this->{$variable}; return $retval; } } $A = new A(); echo "Final Value: " . $A->B->val; ?> That will return something like... Class A::Variable B Class B::Variable val Final Value: 1 It seperates the calls into $A->B and $B->val Hope this helps someone --was-- Since this was getting me for a little bit, I figure I better pipe in here... For nested calls to private/protected variables(probably functions too) what it does is call a __get() on the first object, and if you return the nested object, it then calls a __get() on the nested object because, well it is protected as well. EG: <? class A { protected $B public function __construct() { $this->B = new B(); } public function __get($variable) { echo "Class A::Variable " . $variable . "\n\r"; $retval = $this->{$variable}; return $retval; } } class B { protected $val public function __construct() { $this->val = 1; } public function __get($variable) { echo "Class B::Variable " . $variable . "\n\r"; $retval = $this->{$variable}; return $retval; } } $A = new A(); echo "Final Value: " . $A->B->val; ?> That will return something like... Class A::Variable B Class B::Variable val Final Value: 1 It seperates the calls into $A->B and $B->val Hope this helps someone http://php.net/manual/en/language.oop5.overloading.php

« previous php.notes (#182074) next »