php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27776 arrays in class behave differently than expected
Submitted: 2004-03-30 08:32 UTC Modified: 2004-03-30 08:44 UTC
From: pedja at uzice dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.4 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pedja at uzice dot net
New email:
PHP Version: OS:

 

 [2004-03-30 08:32 UTC] 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.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-30 08:39 UTC] 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:42 UTC] 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:44 UTC] derick@php.net
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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 11:01:36 2025 UTC