note 57632 added to language.references.return

From: Date: Sun, 09 Oct 2005 11:54:40 +0000
Subject: note 57632 added to language.references.return
Groups: php.notes 
Request: Send a blank email to php-notes+get-96751@lists.php.net to get a copy of this message
There is an important difference between php5 and php4 with references. Lets say you have a class with a method called 'get_instance' to get a reference to an exsisting class and it's properties. <?php class mysql { function get_instance(){ // check if object exsists if(empty($_ENV['instances']['mysql'])){ // no object yet, create an object $_ENV['instances']['mysql'] = new mysql; } // return reference to object $ref = &$_ENV['instances']['mysql']; return $ref; } } ?> Now to get the exsisting object you can use mysql::get_instance(); Though this works in php4 and in php5, but in php4 all data will be lost as if it is a new object while in php5 all properties in the object remain. ---- Manual Page -- http://www.php.net/manual/en/language.references.return.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57632 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57632&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57632&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57632&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57632&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57632&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57632&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57632&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57632&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96751) next »