Oh my god, PHP.

For reasons I don’t understand, this does not work (ReflectionException ‘Class Foo does not have a property named prop’):

class Foo
{
    protected static $prop = 'My value';
}

$ref = new ReflectionClass('Foo');
$prop = $ref->getStaticPropertyValue('prop');

However, this does:

$ref = new ReflectionClass('Foo');
$props = $ref->getStaticProperties();
$prop = $props['prop'];

This does not work; PHP cannot dereference array return values:

$props = $ref->getStaticProperties()['prop'];

This does not work; PHP cannot dereference objects from new instances:

$props = new ReflectionClass('Foo')->getStaticProperties();
2008/10/29

Discussion

First one seems like a bug. Did you report it?

Joe Stump
2008/10/29

@Joe Not yet. I’ll let you know when it’s closed as not a bug.

Ian
2008/10/29

That’s just PHP showing you some tough love… like a father who pats his son on the head… while wearing a spiked glove…

Mason
2008/11/03

Participate