php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4054 Strange behavior of class variables
Submitted: 2000-04-05 20:32 UTC Modified: 2002-09-30 18:14 UTC
From: DerMurx at gmx dot de Assigned:
Status: Not a bug Package: Other
PHP Version: 3.0.16 OS: Windows 95/98/NT
Private report: No CVE-ID: None
 [2000-04-05 20:32 UTC] DerMurx at gmx dot de
Have a look at this piece of code:

class User {
  var $Name;
  var $Mail

  function SetUser() {
    $this->$Name = "Bill";
    $this->$Mail = "bill@whitehouse.gov";
    echo $this->$Name, ":", $this->$Mail;
  }
}

Maybe you will notice the mistake with the $ sign ($this->$Name instead of $this->Name, see bug report #60). But PHP doesn't print an error, it interprets the code and outputs this:
bill@whitehouse.gov:bill@whitehouse.gov
So, either PHP should produce an error, or there should be a better description of the missing $ sign in the "Classes and Objects" section of the documentation.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-30 18:14 UTC] hholzgra@php.net
you just descovered "variable variables"

http://www.php.net/manual/en/language.variables.variable.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 30 22:01:28 2024 UTC