note 114541 added to language.references.return

From: Date: Wed, 05 Mar 2014 04:18:15 +0000
Subject: note 114541 added to language.references.return
Groups: php.notes 
Request: Send a blank email to php-notes+get-198792@lists.php.net to get a copy of this message
I learned a painful lesson working with a class method that would pass by reference. In short, if you have a method in a class that is initialed with ampersand during declaration, do not use another ampersand when using the method as in &$this->method(); For example <?php class A { public function &hello(){ static $a=''; return $a; } public function bello(){ $b=&$this->hello(); // incorrect. Do not use ampersand. $b=$this->hello(); // $b is a reference to the static variable. } ?> ---- Server IP: 192.41.45.150 Probable Submitter: 24.185.59.103 ---- Manual Page -- http://php.net/manual/en/language.references.return.php Edit -- https://master.php.net/note/edit/114541 Del: integrated -- https://master.php.net/note/delete/114541/integrated Del: useless -- https://master.php.net/note/delete/114541/useless Del: bad code -- https://master.php.net/note/delete/114541/bad+code Del: spam -- https://master.php.net/note/delete/114541/spam Del: non-english -- https://master.php.net/note/delete/114541/non-english Del: in docs -- https://master.php.net/note/delete/114541/in+docs Del: other reasons-- https://master.php.net/note/delete/114541 Reject -- https://master.php.net/note/reject/114541 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198792) next »