Alex Rivera | Logout

Get a static property of an instance

Asked 2011-04-11T15:43:19.187
20

If I have an instance in PHP, what's the easiest way to get to a static property ('class variable') of that instance ?

This

$classvars=get_class_vars(get_class($thing));
$property=$classvars['property'];

Sound really overdone. I would expect

$thing::property

or

$thing->property

EDIT: this is an old question. There are more obvious ways to do this in newer PHP, search below.

Edit
Report

1 Answer

0
class testClass {
    public static $property = "property value";
    public static $property2 = "property value 2";
}
echo testClass::$property;
echo testClass::property2;
answered 2011-04-11T15:47:34.177

Your Answer