Can static function access non-static variables in php?

php, static-variables

Solution

No. A static method will not have access to `$this` (as there is no `$this` to talk about in a static context).

If you need a reference to the current object within the static method, it is not a static method. You can however access static properties and functions from a non-static method.

Problem

``` <?php class Stat { public $var1='H'; public static $staticVar = 'Static var'; static function check() { echo $this->var1; echo "<br />".self::$staticVar ."<br />"; self::$staticVar = 'Changed Static'; echo self::$staticVar."<br />"; } function check2() { Stat::check(); echo $this->var1; echo "b"; } } ?> ``` Can i use it like this ``` $a = new Stat(); $a->check2(); ```

Original source