Bug #2971: Misbehaved instance variables in classes

From: Date: Mon, 13 Dec 1999 23:57:46 +0000
Subject: Bug #2971: Misbehaved instance variables in classes
Groups: php.dev 
Request: Send a blank email to php-dev+get-13664@lists.php.net to get a copy of this message
From: ojapp@skip-consulting.de Operating system: Linux Suse 6.2 PHP version: 3.0.11 PHP Bug Type: Other Bug description: Misbehaved instance variables in classes Hi, I got a little problem with the following script. The member vars are not set properly. <?php class Option { function Option() { return $this; } } class Select { var $options; var $optionCount=0; function Select() { return $this; } function addOption() { $this->options[$this->optionCount++] = new Option(); echo 'select.addOption() called... optionCount ='.$this->optionCount.'<br>'; } function create() { echo 'select.create() called... optionCount ='.$this->optionCount.'<br>'; } } class Dialog { var $sel; function Dialog() { return $this; } function addSelect() { $this->sel = new Select(); return $this->sel; } function create() { $this->sel->create(); } } $d = new Dialog(); $a = $d->addSelect(); $a->addOption(); $a->addOption(); $d->create(); ?> this script puts out select.addOption() called... optionCount =1 select.addOption() called... optionCount =2 select.create() called... optionCount =0 but it should put out select.addOption() called... optionCount =1 select.addOption() called... optionCount =2 select.create() called... optionCount =2 The member var optionCount is'nt set well. Regards Olaf Japp

« previous php.dev (#13664) next »