Muhammad Haseeb Khan
Muhammad Haseeb Khan

Reputation: 895

Access public static variable outside the class

I have a public variable declared as array in class which is being used locally in class but I'm unable to use it outside the class.

below is the code

class permissions {
    public static $departments = array(
        "Engineering"=>array(
            'ONM','ESS','NP','NC','Engineering'
            )
        );

        // remaining code is left out for brevity

}

How i can access $department in class declaration?

I was expecting this way permissions::departments; but getting error Undefined class constant 'departments'.

Upvotes: 0

Views: 1627

Answers (1)

BlitZ
BlitZ

Reputation: 12168

Try to use combination of scope resolution operator :: and dollar sign $:

print_r(permissions::$departments);

Manual

Upvotes: 3

Related Questions