#30978 [Com]: Append the Object into array result incorrect
| From: | levi at alliancesoftware dot com dot au | Date: | Fri, 17 Dec 2004 02:15:30 +0000 |
| Subject: | #30978 [Com]: Append the Object into array result incorrect | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-70437@lists.php.net to get a copy of this message | ||
ID: 30978
Comment by: levi at alliancesoftware dot com dot au
Reported By: btb_tp at yahoo dot com
Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Windows XP SP2
PHP Version: 5.0.2
New Comment:
This is not a bug, this a result of the new object model in PHP 5. See
http://www.zend.com/php5/articles/engine2-php-oo.php
In PHP 4, the assignment to an object would create a new copy of that
object.
In PHP 5, assignment to an object merely sets a *reference* to that
object, not a copy.
Previous Comments:
------------------------------------------------------------------------
[2004-12-03 19:14:01] btb_tp at yahoo dot com
Description:
------------
Below code work with PHP 4.3.9!!!
Reproduce code:
---------------
class A{
protected $value = 0;
function A($value){
$this->value = $value;}
function getValue(){
return $this->value;}
function setValue($value){
$this->value = $value;}
}
$b = array();
$a = new A(0);
for($i = 1; $i <= 2; $i++){
$a->setValue($i);
$b[] = $a;}
print_r($b);
Expected result:
----------------
Array ( [0] => A Object ( [value:protected] => 1 ) [1] => A Object (
[value:protected] => 2 ) )
Actual result:
--------------
Array ( [0] => A Object ( [value:protected] => 2 ) [1] => A Object (
[value:protected] => 2 ) )
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30978&edit=1