PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > back on bug 42065 , strange behavior with ArrayObject
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
back on bug 42065 , strange behavior with ArrayObject

Réponse
 
LinkBack Outils de la discussion
Vieux 19/09/2007, 09h49   #1 (permalink)
Julien Pauli
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut back on bug 42065 , strange behavior with ArrayObject

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 ?

  Réponse avec citation
Vieux 19/09/2007, 10h07   #2 (permalink)
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] back on bug 42065 , strange behavior with ArrayObject

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/
  Réponse avec citation
Vieux 19/09/2007, 10h21   #3 (permalink)
Julien Pauli
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] back on bug 42065 , strange behavior with ArrayObject

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/
>


  Réponse avec citation
Vieux 20/09/2007, 01h44   #4 (permalink)
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] back on bug 42065 , strange behavior with ArrayObject

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 also
appreciate a patch if possible.

--
Postgresql & php tutorials
http://www.designmagick.com/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h45.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10379 seconds with 12 queries