php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7659 Class variables get confused
Submitted: 2000-11-06 06:14 UTC Modified: 2000-11-06 06:25 UTC
From: awilkins at hmc dot edu Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (06/11/2000) OS: RedHat Linux 6.2
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: awilkins at hmc dot edu
New email:
PHP Version: OS:

 

 [2000-11-06 06:14 UTC] awilkins at hmc dot edu
When this script is run:

<?php
  class Three {
    var $one, $two;

    function Three($a, $b) {
      echo "a is $a; b is $b<br>\n";

      $this->$one = $a;

      echo "one is " . $this->$one . "; two is " . $this->$two . "<br>\n";

      $this->$two = $b;

      echo "one is " . $this->$one . "; two is " . $this->$two . "<br>\n";
    }
  }

  $three = new Three(1, 2);
?>

the results it produces are:

a is 1; b is 2
one is 1; two is 1
one is 2; two is 2

For some reason, it appears as if the two separate variables $one and $two are pointing at the same thing.  This doesn't appear to be a problem that is specific to the constructor, as it happens even if the function involved is only a normal function.  It also occurs if the variables are modified outside of the class.

I also found this bug in 4.0.3pl1, but have not tried any earlier version.  The only module I compiled PHP with was pgsql, if it matters.

Alex Wilkins

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-06 06:25 UTC] stas@php.net
Please read the manual. Syntax is $obj->var, not $obj->$var.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Oct 11 13:00:01 2026 UTC