Re: Bug #962: Inconsistent Object behavior: when referenced from array v. referenced directly

From: Date: Tue, 01 Dec 1998 18:25:38 +0000
Subject: Re: Bug #962: Inconsistent Object behavior: when referenced from array v. referenced directly
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-2632@lists.php.net to get a copy of this message
At 19:16 30/11/98 -0500, dwood@templar.com wrote: >From: dwood@templar.com >Operating system: Win95 >PHP version: 3.0.5 >PHP Bug Type: Other >Bug description: Inconsistent Object behavior: when referenced from array v. referenced directly > >Here we go: > ><? >/////////////////////////////////////////////////////////////////////////// /////// > >class A >{ > var $entries; >} > >class B >{ > var $message; >} > >$newA = new A; > >// Now we pack the A object into an array. >$external_array[0] = $newA; > >$newB = new B; >$newB->message = "testing..."; > >// We put it into A's array: >$newA->entries[] = $newB; > >// Now we get it back directly from the A object: >$temp1 = $newA->entries[0]; // Temp1 should be our B object >print("You'll see the string: ".$temp1->message."<P>"); > >// And then we'll try getting back via the array: >$damaged_by_external_array = $external_array[0]; // This will be our A object (or what's left of it) > >// This is where entries should be empty... >$temp2 = $damaged_by_external_array->entries[0]; // Temp2 should have been our retreived B object. >print("You won't see a thing: ".$temp2->message."<P>"); // >Instead, this line returns an error that temp2 is, in fact, not an object. > >print("<HR>"); >/////////////////////////////////////////////////////////////////////////// /////// > >?> > >I've noticed that if I add the A object to the array _after_ the B object has been >added to $newA->entries, it works fine. > >I'm hoping that when I add something to an array it's not _copied_ into the array - >just referenced there. That would make this a bug. However, I bet everything I put >into an array (including potentially _huge_ objects) probably _are_ copied, aren't they? >Eeesh. Well, if I'm right about that, then is it at least _possible_ to add references >instead of values to an array? I've noticed > >$a[0] = &$myobj; > >generates a parse error. > >Let me just say: languages that usually pass by value are great, but only languages >that usually pass by reference are any good for object oriented coding. That's fine >if the former is more important than the latter... but it'll make this OO junkie >a bit sad... :( I haven't read through the bug description yet, but the last three lines 'automatically' trigger a reply - PHP isn't, in any sort of way, an object oriented language, and was never intended to be one... Zeev -- Zeev Suraski <zeev@php.net> For a PGP public key, finger bourbon@netvision.net.il -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#2632) next »