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

From: Date: Thu, 21 Apr 2005 22:04:44 +0000
Subject: #32789 [Opn->Bgs]: array_pop doesn't work correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-78029@lists.php.net to get a copy of this message
ID: 32789 Updated by: sniper@php.net Reported By: php at thoftware dot de -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: * PHP Version: 4.3.11 New Comment: This works: <?php 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); array_pop($foobar->cache(3)); var_dump($foobar->cache(3)); ?> Ask further support questions on php-general@lists.php.net Previous Comments: ------------------------------------------------------------------------ [2005-04-21 17:34:24] php at thoftware dot de And another thing: As the error occures every time when using a plain function instead of a method (no matter if the functions result is assigned to a variable prior or not), I thought it should be an error giving the result of a function to array_pop(). Or is there any difference between calling a method or calling a function (related to this topic, I mean). ------------------------------------------------------------------------ [2005-04-21 17:28:25] php at thoftware dot de So then pls explain, why this happens: 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']; echo array_pop($foobar->cache(3)); Expected result: ---------------- set at 02:19:11 set at 02:19:11 Actual result: -------------- set at 02:19:11 Fatal error: Only variables can be passed by reference in ... Comment: -------------- If it is passed as variable in the other example, why isn't it passed as variable in this one? Maybe php is bogus, but I don't think this bug-report is ... ------------------------------------------------------------------------ [2005-04-21 17:18:00] sniper@php.net This is how it works. You _are_ passing it a variable. ------------------------------------------------------------------------ [2005-04-21 15:46:03] php at thoftware dot de 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 ------------------------------------------------------------------------ [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). ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/32789 -- Edit this bug report at http://bugs.php.net/?id=32789&edit=1

« previous php.bugs (#78029) next »