note 73476 added to language.oop5.overloading

From: Date: Sat, 24 Feb 2007 22:24:36 +0000
Subject: note 73476 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-123841@lists.php.net to get a copy of this message
As a reply to james at thunder-removeme-monkey dot net, I found that there is a much simpler way to restore the behavior of __get() to 5.1.x state; just force __get() to return by reference, like this: <?php class View { /* Somewhere to store our overloaded properties */ private $v = array(); /* Store a new property */ function __set($varName, $varValue) { $this->v[$varName] = $varValue; } /* Retrieve a property */ function & __get($varName) { if(!isset($this->v[$varName])) { $this->v[$varName] = NULL; } return $this->v[$varName]; } } ?> The only problem is that the code generates a notice if null is returned in __get(), because null cannot be returned by reference. If somebody finds a solution, feel free to email me. :) Cheers ---- Server IP: 82.103.133.188 Probable Submitter: 84.238.32.130 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/73476 Del: integrated -- https://master.php.net/note/delete/73476/integrated Del: useless -- https://master.php.net/note/delete/73476/useless Del: bad code -- https://master.php.net/note/delete/73476/bad+code Del: spam -- https://master.php.net/note/delete/73476/spam Del: non-english -- https://master.php.net/note/delete/73476/non-english Del: in docs -- https://master.php.net/note/delete/73476/in+docs Del: other reasons-- https://master.php.net/note/delete/73476 Reject -- https://master.php.net/note/reject/73476 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123841) next »