note 74571 deleted from function.array-pop by nlopess
| From: | nlopess@php.net | Date: | Tue, 01 May 2007 13:35:17 +0000 |
| Subject: | note 74571 deleted from function.array-pop by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126031@lists.php.net to get a copy of this message | ||
Note Submitter: Omri Bahumi (omri at linuxil dot org)
----
There's a bug (http://bugs.php.net/bug.php?id=25222) with this function in PHP<5 when using
an array of references.
example:
<?php
$obj =& new stdClass();
$arr = array();
$arr[] =& $obj;
$_obj =& array_pop($arr);
$_obj->test = 0;
var_dump($obj);
?>
outputs
object(stdClass)(0) {
}
which means $_obj is not a reference to $obj
workaround:
<?php
$obj =& new stdClass();
$arr = array();
$arr[] =& $obj;
$_obj =& $arr[sizeof($arr) - 1];
array_pop($arr);
$_obj->test = 0;
var_dump($obj);
?>
which outputs
object(stdClass)(1) {
["test"]=>
int(0)
}