note 85904 added to function.array-splice
| From: | madmax at max-worlds dot net | Date: | Wed, 24 Sep 2008 01:23:27 +0000 |
| Subject: | note 85904 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144657@lists.php.net to get a copy of this message | ||
Note: If replacement is not an array, it will be typecast to one (i.e. (array) $parameter). This
may result in unexpected behavior when using an object replacement .
Example :
class A()
{
private $a;
private $b;
public function __construct()
{
$this->a = "foo";
$this->b = "bar";
}
}
$array = array();
array_splice($array, 0, 0, new A());
print_r($array);
Outputs :
Array : Array
{
[0] => foo
[1] => bar
}
Solution : Enforce the array() on the object.
array_splice($array, 0, 0, array(new Object());
Source : http://bugs.php.net/bug.php?id=44485
----
Server IP: 66.207.199.35
Probable Submitter: 70.83.200.50
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- https://master.php.net/note/edit/85904
Del: integrated -- https://master.php.net/note/delete/85904/integrated
Del: useless -- https://master.php.net/note/delete/85904/useless
Del: bad code -- https://master.php.net/note/delete/85904/bad+code
Del: spam -- https://master.php.net/note/delete/85904/spam
Del: non-english -- https://master.php.net/note/delete/85904/non-english
Del: in docs -- https://master.php.net/note/delete/85904/in+docs
Del: other reasons-- https://master.php.net/note/delete/85904
Reject -- https://master.php.net/note/reject/85904
Search -- https://master.php.net/manage/user-notes.php