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

Reply via email to