From: wagner at bonn dot edu Operating system: gentoo linux PHP version: 5.0.4 PHP Bug Type: Scripting Engine problem Bug description: returned a member variable cannot be turned into reference
Description: ------------ When returning a member-variable directly as a reference parameter into a function, a fatal error occurs: Fatal error: Only variables can be passed by reference ... The reproduce code displays the bug (for $case=0) as well as two simple workarounds that IMHO show that the ZEND-Engine should be able to handle this with no need for any error. This seems to have been around for a while, at least PHP 4.3.x Probably related to http://bugs.php.net/bug.php?id=32840 Reproduce code: --------------- $case = 0; function incr(&$int) { return $int++; } class foo { var $v = 1; function &f_ref() { return $this->v; } function f_copy() { return (int)$this->v; } //forced copy through type-cast function f_default() { return $this->v; } } $foo =& new foo(); switch($case) { case 0: //default behaviour is broken echo incr($foo->f_default())."\n"; case 1: //forced reference works AND makes default behaviour work afterwards echo incr($foo->f_ref())."\n"; echo incr($foo->f_default())."\n"; break; case 2: //forced copy works echo incr($foo->f_copy())."\n"; break; } Expected result: ---------------- incr() should get a copy of $foo->v Actual result: -------------- Fatal error: Only variables can be passed by reference in foo.php on line 19 -- Edit bug report at http://bugs.php.net/?id=32841&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32841&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32841&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32841&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32841&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32841&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32841&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32841&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32841&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32841&r=support Expected behavior: http://bugs.php.net/fix.php?id=32841&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32841&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32841&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32841&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32841&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32841&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32841&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32841&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32841&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32841&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32841&r=mysqlcfg
