|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9011 Only one var allowed in a class
Submitted: 2001-01-30 16:09 UTC Modified: 2001-01-30 20:18 UTC
From: artymiak at safenet dot pl Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.3pl1 OS: OpenBSD 2.7
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: artymiak at safenet dot pl
New email:
PHP Version: OS:


 [2001-01-30 16:09 UTC] artymiak at safenet dot 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;



the result is:




Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-30 20:17 UTC]
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
 [2001-01-30 20:18 UTC]
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jul 03 14:01:25 2020 UTC