#27776 [Bgs]: arrays in class behave differently than expected

From: Date: Tue, 30 Mar 2004 13:44:22 +0000
Subject: #27776 [Bgs]: arrays in class behave differently than expected
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-57113@lists.php.net to get a copy of this message
 ID:               27776
 Updated by:       derick@php.net
 Reported By:      pedja at uzice dot net
 Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Windows XP
 PHP Version:      4.3.4
 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.




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

[2004-03-30 08:42:40] iliaa@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

not a bug. 

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

[2004-03-30 08:39:09] pedja at uzice dot net

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

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

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

[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


Thread (4 messages)

« previous php.bugs (#57113) next »