note 110020 added to language.references.pass

From: Date: Wed, 12 Sep 2012 13:26:23 +0000
Subject: note 110020 added to language.references.pass
Groups: php.notes 
Request: Send a blank email to php-notes+get-190653@lists.php.net to get a copy of this message
There seems to be a strange thing happening when passing a variable by reference and assigning that variable to a reference to another variable within the function... case in point: I have this code that is suppose to retrieve an array of data (through mysql_fetch_array(...)) and assign a reference to that array to the "by reference variable" parameter of the function, the array is retrieved fine (I know because I have tested it within the function using print_r()) but the code block that is calling the function sees the variable as null. example: class MyEntries { $last_result = null; $last_entry = null; public function getEntry(&$record) { $this->last_entry = mysql_fetch_array($this->last_result); $record = &$this->last_entry; //print_r($record); // this works fine and is showing the data from the DB. return isset($record['id']) && $record['id']; // I use a non-0 id to initially verify that the entry from the DB is valid ! } } [another php script that includes the script hosting the above class] $myentries = new MyEntries(...); $entry = false; if($myentries->getEntry($entry)) { // problem: runtime gets here but $entry is blank ! } note: within the class the $last_result variable is always a valid mysql query result at the point of the getEntry(..) function's execution. I've just excluded all that code because its alot of code and out of the scope of this post. I cannot figure this one out :(... please help. ---- Server IP: 69.147.83.197 Probable Submitter: 41.117.90.102 ---- Manual Page -- http://www.php.net/manual/en/language.references.pass.php Edit -- https://master.php.net/note/edit/110020 Del: integrated -- https://master.php.net/note/delete/110020/integrated Del: useless -- https://master.php.net/note/delete/110020/useless Del: bad code -- https://master.php.net/note/delete/110020/bad+code Del: spam -- https://master.php.net/note/delete/110020/spam Del: non-english -- https://master.php.net/note/delete/110020/non-english Del: in docs -- https://master.php.net/note/delete/110020/in+docs Del: other reasons-- https://master.php.net/note/delete/110020 Reject -- https://master.php.net/note/reject/110020 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190653) next »