#32789 [Bgs]: array_pop doesn't work correctly
| From: | php at thoftware dot de | Date: | Mon, 25 Apr 2005 20:18:31 +0000 |
| Subject: | #32789 [Bgs]: array_pop doesn't work correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-78175@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: Bogus
Bug Type: Arrays related
Operating System: *
PHP Version: 4.3.11
New Comment:
Maybe this one from Waq explains it in a better way why I think it's a
bug: http://www.php.de/viewtopic.php?p=252840#252840
(it's from a
german forum where the people tried to understand what I tried to
say).
I didn't ask for help, the script that crashed because of this bogus
bug was already fixed when I submitted this. Sorry for taking your
time, surely PHP acts perfect in this case :-(
P.S. Why are you deleting your comments? Do you think it makes it even
more bogus when it looks like I'm talking to myself? Not nice :-(
Previous Comments:
------------------------------------------------------------------------
[2005-04-23 09:05:35] alan_k@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
bugs is not a helpdesk - please leave this as bogus and ask on
php-general.
------------------------------------------------------------------------
[2005-04-22 15:56:37] php at thoftware dot de
Sorry again, maybe I should stop coding %-(, this is the real
Actual result:
--------------
it's forever mine
noone else should be able to change it
it's mine
this is my cache
for the example directly above ...
------------------------------------------------------------------------
[2005-04-22 15:54:09] php at thoftware dot de
Sorry, the fatal error results from the result of cache() being an
empty array (but that may be another bug?), correct code should be:
Reproduce code:
---------------
class foobar {
var $cache = array();
function cache() {
if (!count($this->cache)) {
$this->cache[1] = array(
'this is my cache<br>',
'it\'s mine<br>',
'noone else should be able to change it<br>',
'it\'s forever mine<br>',
);
}
return($this->cache[1]);
}
}
$foobar =& new foobar();
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
Expected result:
----------------
it's forever mine
it's forever mine
it's forever mine
it's forever mine
Actual result:
--------------
Fatal error: Only variables can be passed by reference in ...
Using a static variable within the method will work like the example
using a plain function, using an object-variable will work like shown
above, even if you remove the '[1]'-part.
------------------------------------------------------------------------
[2005-04-22 15:46:13] php at thoftware dot de
And again using an object:
Reproduce code:
---------------
class foobar {
var $cache = array();
function cache() {
if (!isset($this->cache)) {
$this->cache = array(
'this is my cache<br>',
'it\'s mine<br>',
'noone else should be able to change it<br>',
'it\'s forever mine<br>',
);
}
return($this->cache);
}
}
$foobar =& new foobar();
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
echo array_pop($foobar->cache());
Expected result:
----------------
it's forever mine
it's forever mine
it's forever mine
it's forever mine
Actual result:
--------------
Fatal error: Only variables can be passed by reference in ...
Using a static variable within the method will work like the example
using a plain function, using an object-variable causes a fatal error.
------------------------------------------------------------------------
[2005-04-22 15:38:05] php at thoftware dot de
How about this one?
Reproduce code:
---------------
function cache() {
static $cache=array();
if (!count($cache)) {
$cache[1] = array(
'this is my cache<br>',
'it\'s mine<br>',
'noone else should be able to change it<br>',
'it\'s forever mine<br>',
);
}
return($cache[1]);
}
echo array_pop(cache());
echo array_pop(cache());
echo array_pop(cache());
echo array_pop(cache());
Expected result:
----------------
it's forever mine
it's forever mine
it's forever mine
it's forever mine
Actual result:
--------------
it's forever mine
noone else should be able to change it
it's mine
this is my cache
Note: If you remove the '[1]'-part, it works as expected. I think this
part of the problem is not an array_pop()-bug but a bug within the
reference-system?
------------------------------------------------------------------------
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