|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
Hi, at first, read that bug report : http://bugs.php.net/bug.php?id=42065
I would like to say that it doesn't seem to be fixed as it's said. When I execute the bug 42065 test case, it still fails. In reality, another code brought me to that bug, please consider this : <?php class a { public $array = array('key'=>'2'); public function getArray() { return $this->array; } } $a = new a; $tab = $a->getArray(); $tab['key'] = 5; print_r($a); print_r($tab); Outputs : a Object ( [array] => Array ( [key] => 2 ) ) Array ( [key] => 5 ) No problem, that's expected. Now consider that : $a = new a; $tab = new ArrayObject($a->getArray()); $tab['key'] = 5; print_r($a); print_r($tab); Outputs : a Object ( [array] => Array ( [key] => 5 ) ) ArrayObject Object ( [key] => 5 ) So, the original array, inside the 'a' object has been modified, but it souldn't have. This behavior is like the one described in bug 42065 Plateform : Windows PHP : latest 5.2 snapshot - Apache SAPI. If you really want the original array not to be modified, you should act like this : $tab = new ArrayObject((array)$a->getArray()); Strange isn't it ? |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
Julien Pauli wrote:
> Hi, at first, read that bug report : http://bugs.php.net/bug.php?id=42065 > > I would like to say that it doesn't seem to be fixed as it's said. > When I execute the bug 42065 test case, it still fails. > > In reality, another code brought me to that bug, please consider this : http://www.php.net/manual/en/functio...ruct.php#77235 Says it all ![]() -- Postgresql & php tutorials http://www.designmagick.com/ |
|
|
|
#3 (permalink) |
|
Messages: n/a
Hébergeur: |
Wow, all right ; that's why casting to (array) before passing the variable ,
thus making a copy of it, works. Thanks for that short but effective answer ;-) However, except in the comments, this is not said in the original doc. It should be written ArrayObject ArrayObject::__construct ( mixed &$input ) shouldn't it ? 2007/9/19, Chris <dmagick@gmail.com>: > > Julien Pauli wrote: > > Hi, at first, read that bug report : > http://bugs.php.net/bug.php?id=42065 > > > > I would like to say that it doesn't seem to be fixed as it's said. > > When I execute the bug 42065 test case, it still fails. > > > > In reality, another code brought me to that bug, please consider this : > > http://www.php.net/manual/en/functio...ruct.php#77235 > > Says it all ![]() > > -- > Postgresql & php tutorials > http://www.designmagick.com/ > |
|
|
|
#4 (permalink) |
|
Messages: n/a
Hébergeur: |
Julien Pauli wrote:
> Wow, all right ; that's why casting to (array) before passing the > variable , thus making a copy of it, works. > Thanks for that short but effective answer ;-) > > However, except in the comments, this is not said in the original doc. > It should be written > ArrayObject ArrayObject::__construct ( mixed &$input ) > shouldn't it ? I guess it's time to post a documentation bug I'm sure they'd alsoappreciate a patch if possible. -- Postgresql & php tutorials http://www.designmagick.com/ |
|
![]() |
| Outils de la discussion | |
|
|