note 105176 added to language.oop5.overloading

From: Date: Mon, 01 Aug 2011 15:38:52 +0000
Subject: note 105176 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-182071@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: <? 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 ---- Server IP: 69.147.83.197 Probable Submitter: 50.72.67.8 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/105176 Del: integrated -- https://master.php.net/note/delete/105176/integrated Del: useless -- https://master.php.net/note/delete/105176/useless Del: bad code -- https://master.php.net/note/delete/105176/bad+code Del: spam -- https://master.php.net/note/delete/105176/spam Del: non-english -- https://master.php.net/note/delete/105176/non-english Del: in docs -- https://master.php.net/note/delete/105176/in+docs Del: other reasons-- https://master.php.net/note/delete/105176 Reject -- https://master.php.net/note/reject/105176 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182071) next »