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();

3 Responses to “Oh my god, PHP.”

  1. Joe Stump Says:

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

  2. Ian Says:

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

  3. Mason Says:

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

Leave a Reply