From:             espiao at gmail dot com
Operating system: Debian
PHP version:      5.1.2
PHP Bug Type:     Arrays related
Bug description:  Array of object's problem

Description:
------------
I'm using an array of objects and when I copy the array to an another
array structure this will referencing, not copying.
I tried to use copy() statement, but it works only to objects,
off-course.
Soorry by bad english.

Reproduce code:
---------------
class slaveObject {
  public $singleVar;
  public __construct($mySingleVar) { $this->sigleVar = $mySingleVar; }
}
class mainObject {
  public $objects = array();
  public __construct() {
    $this->objects[] = new slaveObject('Example1');
    $this->objects[] = new slaveObject('Example2');
    $this->objects[] = new slaveObject('Example3');
  }
}

$myObject = &new mainObject();
$myObjectArray = $myObject->objects;
print_r($myObject->objects);
$myObjectArray[0]->singleVar = 'Example4';
print_r($myObject->objects);
print_r($myObjectArray);

Expected result:
----------------
Array(
  [0] => slaveObject (
    [singleVar] => Example1
  )
  [1] => slaveObject (
    [singleVar] => Example2
  )
  [2] => slaveObject (
    [singleVar] => Example3
  )
)
Array(
  [0] => slaveObject (
    [singleVar] => Example1
  )
  [1] => slaveObject (
    [singleVar] => Example2
  )
  [2] => slaveObject (
    [singleVar] => Example3
  )
)
Array(
  [0] => slaveObject (
    [singleVar] => Example4
  )
  [1] => slaveObject (
    [singleVar] => Example2
  )
  [2] => slaveObject (
    [singleVar] => Example3
  )
)

Actual result:
--------------
Array(
  [0] => slaveObject (
    [singleVar] => Example1
  )
  [1] => slaveObject (
    [singleVar] => Example2
  )
  [2] => slaveObject (
    [singleVar] => Example3
  )
)
Array(
  [0] => slaveObject (
    [singleVar] => Example4
  )
  [1] => slaveObject (
    [singleVar] => Example2
  )
  [2] => slaveObject (
    [singleVar] => Example3
  )
)
Array(
  [0] => slaveObject (
    [singleVar] => Example4
  )
  [1] => slaveObject (
    [singleVar] => Example2
  )
  [2] => slaveObject (
    [singleVar] => Example3
  )
)

-- 
Edit bug report at http://bugs.php.net/?id=37231&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=37231&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=37231&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=37231&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=37231&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=37231&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=37231&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=37231&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=37231&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=37231&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=37231&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=37231&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=37231&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=37231&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=37231&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=37231&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=37231&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=37231&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=37231&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=37231&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=37231&r=mysqlcfg

Reply via email to