FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » ArrayObject - copy or reference
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: ArrayObject - copy or reference [message #175175 is a reply to message #175173] Thu, 18 August 2011 23:26 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 8/18/2011 2:44 PM, Thomas Mlynarczyk wrote:
> Jerry Stuckle schrieb:
>
>> I get 1 here also (php 5.2.4). I would consider this a bug - you might
>> want to post it to bugs.php.net.
>
> But the bug was in 5.2.0 and seems now fixed in 5.2.4. Please look at my
> code example again. I start with an array $array. Then I use that to
> create an ArrayObject $obj, which should be a *copy* of $array, not a
> reference to it. Now, whatever I do to $obj should not modify $array:
>
> $array = array( 1, 2, 3 );
> $obj = new ArrayObject( $array );
> $obj[0] = 42;
> echo $obj[0]; // This should print 42 and it does
> echo '<br>';
> echo $array[0]; // This should print 1 and it does in 5.2.4
>
> From your and Jo's postings I get the impression that you both think
> that $obj should be a reference to $array instead of an independent
> copy. But the docs do not mention any passing by reference (like
> "&$input"):
>
> ArrayObject::__construct() ([ mixed $input [, int $flags [, string
> $iterator_class ]]] )
>
> There is, however, a user comment addressing this issue and giving a
> code example almost identical to mine:
>
> <quote>Note that the first argument to ArrayObject::__construct, the
> initial array, is passed by reference. ...</quote>
>
> Considering the date of that comment, it certainly refers to the old
> "pre-5.2.4" behaviour.
>
> Do you think this change in behaviour was unintentional (and thus not
> meant to be a bugfix) and nobody has noticed it so far and that's why I
> cannot find any official documentation about it? Anyway, I think the new
> behaviour is the "correct" one -- I would not expect $array to be passed
> by reference when it's not explicitly documented. Also, this behaviour
> makes more sense to me.
>
> Greetings,
> Thomas
>
>

Yes, I think it's a bug in 5.2.0. But thinking more of it, I guess they
won't accept a bug against 5.2.0 any more.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Freelance PHP Developer
Next Topic: How to integrate paypal payment Indian currency support ..?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 02:06:29 GMT 2024

Total time taken to generate the page: 0.04916 seconds