Ondra Zizka wrote: > Hello, > > please look at the code bellow and tell if it does not conform to rules of > returning a reference from a function. > In the first method, I return reference to $sRet variable, and PHP is quiet. > But in the second, PHP says: > > Notice: Only variable references should be returned by reference in > C:\web\php_bug_reference_return.php on line 8 // return $ref =& > $this->ReturnReference(); > (Note that the notice does not concern the first method as the notice > appears even if I remove references from the first method.) > > But I am still just returning a reference to a variable, are you? seems like your returning a reference to the result of an expression, in both cases. > so I guess it's > actually correct, isn't it? > > Thanks for oppinions. > Ondra Zizka > > > <?php > class A { > function &ReturnReference(){ > $sFoo = "Hi."; > return $sRet =& $sFoo; > } > function &RequireReference(){ > return $ref =& $this->ReturnReference(); > } > } > > $oA = new A(); > $ref = $oA->RequireReference(); class A { function &ReturnReference(){ $sFoo = "Hi."; $sRet =& $sFoo; return $sRet; } function &RequireReference() { $ref =& $this->ReturnReference(); return $ref; } } $oA = new A(); $ref = $oA->RequireReference(); the above runs without notices, which should show the difference between the result of an expression and a variable that might contain it. > ?> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php