ID:               27776
 User updated by:  pedja at uzice dot net
 Reported By:      pedja at uzice dot net
 Status:           Open
 Bug Type:         Arrays related
 Operating System: Windows XP
 PHP Version:      4.3.4
 New Comment:

Hmm... i found out what was the problem.



Instead of $this->$testarray[$counter] i should use
$this->testarray[$counter]


Previous Comments:
------------------------------------------------------------------------

[2004-03-30 08:32:14] pedja at uzice dot net

Description:
------------
I created array as class property. It does not work as expected. Here
is an example:



<?php



  class testclass { 

    var $testarray = array();

  

    function testclass() {

      for ($counter = 65; $counter < 75; $counter++) {

        $this->$testarray[$counter] = chr ($counter);

      }

    }

    

  }

  

  $testvar = new testclass();

  print_r ($testvar->$testarray);



?>



The result of this code is array containing one record. It should
contain several records.



If I cahnge this code to use global variable instead of class property
... 



<?php



  class testclass { 

  

    function testclass() {

      global $testarray;

      

      for ($counter = 65; $counter < 75; $counter++) {

        $testarray[$counter] = chr ($counter);

      }

    }

    

  }

  

  $testvar = new testclass();

  print_r ($testarray);



?>



... it works: I get what I expected - array containing several
records.





------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27776&edit=1

Reply via email to