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

From: Date: Tue, 30 Mar 2004 13:32:14 +0000
Subject: #27776 [NEW]: arrays in class behave differently than expected
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-57107@lists.php.net to get a copy of this message
From:             pedja at uzice dot net
Operating system: Windows XP
PHP version:      4.3.4
PHP Bug Type:     Arrays related
Bug description:  arrays in class behave differently than expected

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 bug report at http://bugs.php.net/?id=27776&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27776&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27776&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27776&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27776&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27776&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27776&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27776&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27776&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27776&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27776&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27776&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27776&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27776&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27776&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27776&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27776&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27776&r=float


Thread (4 messages)

« previous php.bugs (#57107) next »