Reputation: 24099
I have a var in my class
protected $test = 'test';
Normally I would access this inside the class like:
$this->test;
But this gives me an error.
How can I access vars inside a static class?
Upvotes: 1
Views: 53
Reputation: 982
Try this:
//declare
protected $test = 'test';
public $publicTest = 'test';
//access this inside the class
self::$test;
//access this inside the class on dynamic instance
static::$publicTest;
Upvotes: 0
Reputation: 27325
You have to declare the variable as static
first.
static $test = 'test';
After that you can access it with self::$test
Upvotes: 3