Skip to content

Static properties fail to be accessed through RuntimeReflectionProperty #420

@melkamar

Description

@melkamar

Bug Report

Q A
Version 3.3.3
Previous Version if the bug is a regression 2.5.7

Summary

After upgrading 2.5.7 → 3.3.3 as a dependency of the Doctrine ODM we are seeing crashes:

Cannot assign null to property RH\OrganisationBundle\Model\Organisation::$type of type string

The catch here is that the $type property is static. But it has been like this for years and years in our codebase and worked OK.

This happens when running the UnitOfWork->merge() method. I have tracked this down to the RuntimeReflectionProperty behaving differently from the native ReflectionProperty for static properties:

<?php

require 'vendor/autoload.php';

class Foo
{
    public static $staticProp = 'staticPropValue';
}

$fooInstance = new Foo();

$propNative = new ReflectionProperty(Foo::class, 'staticProp');
$propDoctrine = new \Doctrine\Persistence\Reflection\RuntimeReflectionProperty(Foo::class, 'staticProp');

var_dump(
    $propNative->getValue(),
    $propNative->getValue($fooInstance),
    $propDoctrine->getValue(),
    $propDoctrine->getValue($fooInstance)
);

/*
 * string(15) "staticPropValue"
 * string(15) "staticPropValue"
 * string(15) "staticPropValue"
 * NULL
 */

I believe this has been introduced in 45c484f.

Current behavior

RuntimeReflectionProperty returns null for static properties.

Expected behavior

RuntimeReflectionProperty should return actual values for static properties.

How to reproduce

See linked PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions