2

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,

0

1 Answer 1

4

You need to use $$:

self::$$variable_name;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.