Class A has a member with a function:
class A {
public function foo() {
static $x=2;
function bar() {
echo "x=$x";
}
bar();
}
}
$a = new A();
$a->foo();
This gives an error in line echo "x=$x";.
How to access $x from class member foo() in function bar()?
I'm using PHP 5.5.9.
self::$x?FATAL ERROR Cannot access self:: when no class scope is active....$xis no static class member!$xis out of scope forbar(). There's several options, here's one of them.$x?