PHP 4.0 Bug #9011 Updated: Only one var allowed in a class

From: Date: Wed, 31 Jan 2001 01:17:45 +0000
Subject: PHP 4.0 Bug #9011 Updated: Only one var allowed in a class
Groups: php.dev 
Request: Send a blank email to php-dev+get-45405@lists.php.net to get a copy of this message
ID: 9011 Updated by: lyric Reported By: artymiak@safenet.pl Status: Open Bug Type: *General Issues Assigned To: Comments: You should use $this->balance, not $this->$balance. The latter is equivalent to $this->'', where all your values are being stored. If possible, you might consider raising the error_reporting level in your php.ini Previous Comments: --------------------------------------------------------------------------- [2001-01-30 16:09:25] artymiak@safenet.pl The following class definition lists three vars, yet they are all treated as one, as the call to report() shows. I'd love to be able to define more vars in a class. <? class bankaccount { var $balance; var $transactions; var $history; function bankaccount () { $this->$balance = 0.00; $this->$transactions = 0; $this->$history[$transactions] = $this->$balance; } function report () { echo $this->$balance . "<br>"; echo $this->$transactions . "<br>"; echo $this->$history[$transactions] . "<br>"; } function credit ($amount) { $amount = abs($amount); $this->$balance += $amount; } function debit ($amount) { $amount = abs($amount); $this->$balance -= $amount; } } $USDaccount = new bankaccount; $USDaccount->credit(10000); $USDaccount->debit(1000); $USDaccount->debit(.78); $USDaccount->report(); ?> the result is: 8999.22 8999.22 8999.22 Why? --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=9011

« previous php.dev (#45405) next »