Issue
class A {
protected $bar = 'bar';
public function foo() {
echo $this->$bar;
}
}
$a = new A();
$a->foo();
It's boggling my mind that this isn't working. I come from C++ and C# so it's likely something I don't understand about PHP.
Solution
When you access a member, you only need the dollar-sign before this
; i.e. access it like this instead:
echo $this->bar;
Answered By - Peter Bloomfield Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.