Skip to content

BUG: get_object_vars in ObjectAccess::initializePropertyGetterCache only takes initialized properties into account #3545

Description

@sorenmalling

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

With a class containing the follow properties

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: true)]
    public ?Identity $identity = null;

    #[ORM\ManyToOne(inversedBy: 'people')]
    #[ORM\JoinColumn(nullable: false)]
    public Network $network;

only the property $identity is returned in get_object_vars($subject)

https://github.com/neos/flow-development-collection/blob/9.2/Neos.Utility.ObjectHandling/Classes/ObjectAccess.php#L194-L196

This means, that validation is breaking, as the validator can't access non-initialized properties.

This is intended behavior of that function described in the note on php.net
https://www.php.net/manual/en/function.get-object-vars.php

Expected Behavior

All public properties should be seen by the ObjectAccess.

Solvable with ReflectionClass

Changing this to using the ReflectionClass functionality we can get all public properties

        $properties = array_map(fn(\ReflectionProperty $property) => $property->getName(), (new \ReflectionClass($subject))->getProperties(\ReflectionProperty::IS_PUBLIC));

        if (in_array($propertyName, $properties)) {
            self::$propertyGetterCache[$cacheIdentifier]['publicProperty'] = $propertyName;
        }

Steps To Reproduce

No response

Environment

- Flow: 9.1.1
- PHP: 8.5

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions