#32789 [Fbk->Opn]: array_pop doesn't work correctly

From: Date: Thu, 21 Apr 2005 13:46:04 +0000
Subject: #32789 [Fbk->Opn]: array_pop doesn't work correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-77992@lists.php.net to get a copy of this message
ID: 32789 User updated by: php at thoftware dot de Reported By: php at thoftware dot de -Status: Feedback +Status: Open Bug Type: Arrays related Operating System: Windows PHP Version: 4.3.9 New Comment: O.k., this for a new start, sorry for inconvenience: Description: ------------ array_pop() removes data from objects via a method. Seems that the first call with a method isn't recognized as being not a variable =8-0. Reproduce code: --------------- class foobar { var $cache = array(); function cache($j) { if (!isset($this->cache[$j])) { $this->cache[$j] = array( 'wert' => $j, 'text' => 'value: '.$j.'<br>', 'time' => 'set at '.date('h:i:s').'<br>', ); } return($this->cache[$j]); } } $foobar =& new foobar(); echo array_pop($foobar->cache(3)); echo array_pop($foobar->cache(3)); echo array_pop($foobar->cache(3)); echo array_pop($foobar->cache(3)); Expected result: ---------------- set at 02:19:11 set at 02:19:11 set at 02:19:11 set at 02:19:11 resp. Fatal error: Only variables can be passed by reference in ... Actual result: -------------- set at 02:19:11 value: 3 3 Previous Comments: ------------------------------------------------------------------------ [2005-04-21 15:27:34] tony2001@php.net Then please explain the problem more clearly because the code you gave is not understandable. The main questions are: what did you expect? what did you get? Also, please try newer version before reporting (the latest 4.3.x version ATM is 4.3.11). ------------------------------------------------------------------------ [2005-04-21 15:21:44] php at thoftware dot de As there are 4 code-sniplets with 4 different results, I thought it would be a good idea to show the results as comments with the corresponding code. I don't think it would be more readable otherwise. ------------------------------------------------------------------------ [2005-04-21 15:11:00] tony2001@php.net Please fill in expected & actual results fields. ------------------------------------------------------------------------ [2005-04-21 14:59:37] php at thoftware dot de Description: ------------ array_pop() removes data from objects via a method. Reproduce code: --------------- class foobar { var $cache = array(); function cache($j) { if (!isset($this->cache[$j])) { $this->cache[$j] = array( 'wert' => $j, 'text' => 'value: '.$j.'<br>', 'time' => 'set at '.date('h:i:s').'<br>', ); } return($this->cache[$j]); } } $foobar =& new foobar(); $v = $foobar->cache(3); echo $v['time']; $v = $foobar->cache(3); echo $v['time']; $v = $foobar->cache(3); echo $v['time']; $v = $foobar->cache(3); echo $v['time']; /* returns as expected set at 02:19:11 set at 02:19:11 set at 02:19:11 set at 02:19:11 */ $foobar =& new foobar(); echo array_pop($foobar->cache(3)); /* returns as desired set at 02:19:11 */ $foobar =& new foobar(); echo array_pop($foobar->cache(3)); echo array_pop($foobar->cache(3)); echo array_pop($foobar->cache(3)); echo array_pop($foobar->cache(3)); /* returns as not desired set at 02:19:11 value: 3 3 */ $foobar =& new foobar(); $v = $foobar->cache(3); echo $v['time']; echo array_pop($foobar->cache(3)); /* returns as it should set at 02:19:11 Fatal error: Only variables can be passed by reference in ... */ Seems that the first call with a method isn't recognized as being not a variable =8-0. Expected result: ---------------- see above Actual result: -------------- see above ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32789&edit=1

« previous php.bugs (#77992) next »