Mantis - Quercus
Viewing Issue Advanced Details
4310 major always 11-30-10 12:32 03-22-12 13:41
gspeicher  
 
normal  
assigned 4.0.13  
open  
none    
none  
0004310: inconsistent behavior for declared attributes when accessed from member functions versus public member access
Declaring attributes in user-defined classes results in the following problematic situation:

class A {
  public $x = 1;
  public function __construct() {
    $this->x = 2;
  }
  public function foo() {
    return $this->x;
  }
}

$a = new A();
print "a.x: " . $a->x . "
\n";
print "a.foo(): " . $a->foo() . "
\n";


class B {
  # note no declaration for x
  public function __construct() {
    $this->x = 2;
  }
  public function foo() {
    return $this->x;
  }
}

$b = new B();
print "b.x: " . $b->x . "
\n";
print "b.foo(): " . $b->foo() . "
\n";


Expected output:
a.x: 2
a.foo(): 2
b.x: 2
b.foo(): 2

Actual output:
a.x: 1
a.foo(): 2
b.x: 2
b.foo(): 2

There are no notes attached to this issue.