#43983 [Fbk->Opn]: Weird referencing with stdClass objects
| From: | rubens21 at gmail dot com | Date: | Sun, 24 Feb 2008 20:17:54 +0000 |
| Subject: | #43983 [Fbk->Opn]: Weird referencing with stdClass objects | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122658@lists.php.net to get a copy of this message | ||
ID: 43983
User updated by: rubens21 at gmail dot com
Reported By: rubens21 at gmail dot com
-Status: Feedback
+Status: Open
Bug Type: Scripting Engine problem
PHP Version: 5.2.5
New Comment:
I'm sorry, 'The same' = 'The same problem'
CODE:
$test = new stdClass();
$Objeto = new stdClass();
$test->valor = "The first value";
$Objeto->valorDeTeste[] = $test;
$test->valor = "The second value";
echo "<pre>";
print_r($Objeto->valorDeTeste);
echo "<br />";
var_dump($Objeto->valorDeTeste);
echo "</pre>";
Array
(
[0] => stdClass Object
(
[valor] => The second value
)
)
array(1) {
[0]=>
object(stdClass)#1 (1) {
["valor"]=>
string(16) "The second value"
}
}
Previous Comments:
------------------------------------------------------------------------
[2008-02-24 19:44:21] jani@php.net
That's impossible, the output of var_dump() differs a LOT from
print_r(). So can you please really test it?
------------------------------------------------------------------------
[2008-02-23 17:04:12] rubens21 at gmail dot com
"What does it output when you replace print_r() with var_dump() ?"
R: The same
------------------------------------------------------------------------
[2008-02-01 22:28:15] jani@php.net
What does it output when you replace print_r() with var_dump() ?
------------------------------------------------------------------------
[2008-01-30 15:40:53] rubens21 at gmail dot com
This example is more simple:
$test = new stdClass();
$Objeto = new stdClass();
$test->valor = "The first value";
$Objeto->valorDeTeste[] = $test;
$test->valor = "The second value";
print_r($Objeto->valorDeTeste);
Expected:
Array
(
[0] => stdClass Object
(
[valor] => The first value
)
)
Actual
Array
(
[0] => stdClass Object
(
[valor] => The second value
)
)
------------------------------------------------------------------------
[2008-01-30 15:37:54] rubens21 at gmail dot com
Description:
------------
change atribute of a class, and arrays that received values is change
too.
I know that the bug #33207
(http://bugs.php.net/bug.php?id=33207&edit=2) describes this same
problem, but there is not the solution and the id of the other related.
Reproduce code:
---------------
$test = new stdClass();
$Objeto = new stdClass();
$test->valor = "No Change!";
$Objeto->valorDeTeste[] = $test;
$test->valor = "Yes, change!";
$Objeto->valorDeTeste[] = $test;
print_r($Objeto->valorDeTeste);
Expected result:
----------------
Array
(
[0] => stdClass Object
(
[valor] => No Change!
)
[1] => stdClass Object
(
[valor] => Yes, change!
)
)
Actual result:
--------------
Array
(
[0] => stdClass Object
(
[valor] => Yes, change!
)
[1] => stdClass Object
(
[valor] => Yes, change!
)
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43983&edit=1