Ted
Ted

Reputation: 4166

PHP: request static property from variable value

Is there a way to access class static property using variable value, like below:

class test
{
    private static $test_var = 4444;
    public function get_data()
    {
        $variable_name = 'test_var';
        return self::{$variable_name}; //returns:4444,
    }
} 

thx,

Upvotes: 2

Views: 44

Answers (1)

Krzysztof Atłasik
Krzysztof Atłasik

Reputation: 22625

You need to use $$:

self::$$variable_name;

Upvotes: 4

Related Questions