470,874 Members | 1,435 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

Object in array turns into reference when I access it.


Can anyone explain this? I'm running PHP Version 4.3.7

<?php
class foo {
function bar() {
}
}

$array["foo"] = new foo();

var_dump($array);
// Returns:
// array(1) {
// ["foo"]=>
// object(foo)(0) {
// }
// }

$array["foo"]->bar();

var_dump($array);
// Returns
// array(1) {
// ["foo"]=>
// &object(foo)(0) { <-- How did that happen?
// }
// }
?>
--

__o Alex Farran - PHP / MySQL Web application development
_`\<,_ site: www.alexfarran.com phone: 01273 474065
(_)/ (_) blog: alexfarran.blogspot.com mobile: 07790 389330
Jul 17 '05 #1
4 1416
Alex Farran wrote:
Can anyone explain this? I'm running PHP Version 4.3.7


See: http://bugs.php.net/bug.php?id=11543
JW

Jul 17 '05 #2
Janwillem Borleffs writes:
Alex Farran wrote:
Can anyone explain this? I'm running PHP Version 4.3.7
See: http://bugs.php.net/bug.php?id=11543


Thank you. So it is a bug. The last comment talks about the
__clone() method in Zend 2, which seems slightly tangential to the
problem. Can someone with PHP5 installed run my script and show me
what happens?

--

__o Alex Farran - PHP / MySQL Web application development
_`\<,_ site: www.alexfarran.com phone: 01273 474065
(_)/ (_) blog: alexfarran.blogspot.com mobile: 07790 389330
Jul 17 '05 #3
Alex Farran wrote:
Can someone with PHP5 installed run my script and show me
what happens?


Yes:

array(1) {
["foo"]=>
object(foo)#1 (0) {
}
}
array(1) {
["foo"]=>
object(foo)#1 (0) {
}
}

HTH,

PS: I used the script you gave in the first post, if you need me to test
another, i'd love to help.

Best regards,
Sebastian
Jul 17 '05 #4
Sebastian Lauwers writes:
Alex Farran wrote:
Can someone with PHP5 installed run my script and show me
what happens?
Yes:


Thanks. That's much more sensible behaviour. One more reason to
switch to PHP5 ASAP.

--

__o Alex Farran - PHP / MySQL Web application development
_`\<,_ site: www.alexfarran.com phone: 01273 474065
(_)/ (_) blog: alexfarran.blogspot.com mobile: 07790 389330
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by lawrence | last post: by
5 posts views Thread by simon place | last post: by
28 posts views Thread by Daniel | last post: by
5 posts views Thread by Michael Moreno | last post: by
272 posts views Thread by Peter Olcott | last post: by
1 post views Thread by BiraRai | last post: by
275 posts views Thread by Astley Le Jasper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.