From:             neoglez at gmail dot com
Operating system: MWindows Prof. V.2002 SP3
PHP version:      5.2SVN-2009-10-23 (snap)
PHP Bug Type:     Class/Object related
Bug description:  Array member of a class is not well populated

Description:
------------
When a member of a class(let's say class A)is an array of objects from
other class B (who has a member that is an array too) and i want to
populate the $this->member from the class A using
$this->member[]=$some_object_of_class_b it does increase the number of
elements in the array BUT IT OVERWRITES ALL ELEMENTS VALUE OF THE
$this->member ARRAY.

Reproduce code:
---------------
class A{
  public $arry = array();
  public function set_array($array){
    $this->arry = $array;} 
}
class B{
  public $array_of_object;
  public function add_object($object){
    $this->array_of_object[] = $object;
  }
}
$array = array('I' => 'you');
$a = new A();
$b = new B();
for($i=0 ; $i < 3 ; $i++){
      $array1 = array($i=>'he'); 
      $array = array_merge($array, $array1);
      $a->set_array($array);      
      $b->add_object($a);}
var_dump($b);

Expected result:
----------------
object(B)#2 (1) {
  ["array_of_object"]=>
  array(3) {
    [0]=>
    object(A)#1 (1) {
      ["arry"]=>
      array(2) {
        ["I"]=>
        string(3) "you"
        [0]=>
        string(2) "he"
      }
    }
    [1]=>
    object(A)#1 (1) {
      ["arry"]=>
      array(3) {
        ["I"]=>
        string(3) "you"
        [0]=>
        string(2) "he"
        [1]=>
        string(2) "he"
      }
    }
    [2]=>
    object(A)#1 (1) {
      ["arry"]=>
      array(4) {
        ["I"]=>
        string(3) "you"
        [0]=>
        string(2) "he"
        [1]=>
        string(2) "he"
        [2]=>
        string(2) "he"
      }
    }
  }
}


Actual result:
--------------
object(B)#2 (1) {
  ["array_of_object"]=>
  array(3) {
    [0]=>
    object(A)#1 (1) {
      ["arry"]=>
      array(4) {
        ["I"]=>
        string(3) "you"
        [0]=>
        string(2) "he"
        [1]=>
        string(2) "he"
        [2]=>
        string(2) "he"
      }
    }
    [1]=>
    object(A)#1 (1) {
      ["arry"]=>
      array(4) {
        ["I"]=>
        string(3) "you"
        [0]=>
        string(2) "he"
        [1]=>
        string(2) "he"
        [2]=>
        string(2) "he"
      }
    }
    [2]=>
    object(A)#1 (1) {
      ["arry"]=>
      array(4) {
        ["I"]=>
        string(3) "you"
        [0]=>
        string(2) "he"
        [1]=>
        string(2) "he"
        [2]=>
        string(2) "he"
      }
    }
  }
}

-- 
Edit bug report at http://bugs.php.net/?id=49964&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49964&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49964&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49964&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49964&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49964&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49964&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49964&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49964&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49964&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49964&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49964&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49964&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49964&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49964&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49964&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49964&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49964&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49964&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49964&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49964&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49964&r=mysqlcfg

Reply via email to