PHP5: class variables problem / array_push bug

From: Date: Thu, 05 Feb 2004 12:46:00 +0000
Subject: PHP5: class variables problem / array_push bug
References: 1  Groups: php.qa 
Request: Send a blank email to php-qa+get-15923@lists.php.net to get a copy of this message
hi at all, i've a very strange problem but i don't know if this a real bug or only my imcompetence?! it is a problem with class variables set by __constructor() function in PHP5... look at this code: <?    class MyClass extends DomNode {      // remove "extends DomNode" and everything is fine       private $__arr = Array();       public function __construct() {          //$this->__arr = Array();      // uncomment this line for testing          $this->__setVar("value set inside constructor");       }       public function __setVar($classname) {          print("\n\nexecuting __setVar()\n");          print("trying to push \"" . $classname . "\" into \$this->__arr with array_push\n");          // array_push only works in several cases...          array_push($this->__arr, $classname);          // comment following line for testing          //$this->__arr[] = $classname;           /*          foreach($this->__arr as $parentClassname) {             print($parentClassname . "\n");          }          */       }    }             print("<pre>");    $node = new MyClass();    print_r($node);    $node->__setVar("value set outside object method");    print_r($node);    print("</pre>"); ?> output: ******************************************* executing __setVar() trying to push "value set inside constructor" into $this->__arr with array_push MyClass Object (     [__arr:private] => Array         (         ) ) executing __setVar() trying to push "value set outside object method" into $this->__arr with array_push MyClass Object (     [__arr:private] => Array         (             [0] => value set outside object method         ) ) ******************************************* ok, in my opinion the Array $this->_arr should have a value "value set inside constructor" after creating the object set by array_push (see output line 2)! But there are several cases in which this bug does not appear: - remove "extends DomNode" from code and it works fine         ...but what does DomNode with my __construct() function?! - uncomment line 6 and it will work         ...don't ask me why it works now?! - uncomment line 19 and it will work         ...seens that array_push does not work correctly. by the way i'm using PHP5 cvs-version from 2004-05-02 10:30... maybe you could help me out of this dilemma.. another question for the php experts: is this information enough for sending a bug to php.bugs? thanks for your attention. bye vivi

« previous php.qa (#15923) next »