note 74571 added to function.array-pop

From: Date: Tue, 17 Apr 2007 23:27:00 +0000
Subject: note 74571 added to function.array-pop
Groups: php.notes 
Request: Send a blank email to php-notes+get-125534@lists.php.net to get a copy of this message
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) } ---- Server IP: 192.117.122.43 Probable Submitter: 87.69.48.118 ---- Manual Page -- http://www.php.net/manual/en/function.array-pop.php Edit -- https://master.php.net/note/edit/74571 Del: integrated -- https://master.php.net/note/delete/74571/integrated Del: useless -- https://master.php.net/note/delete/74571/useless Del: bad code -- https://master.php.net/note/delete/74571/bad+code Del: spam -- https://master.php.net/note/delete/74571/spam Del: non-english -- https://master.php.net/note/delete/74571/non-english Del: in docs -- https://master.php.net/note/delete/74571/in+docs Del: other reasons-- https://master.php.net/note/delete/74571 Reject -- https://master.php.net/note/reject/74571 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125534) next »