neos / neos/flow-development-collection

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

Open Beginner friendly
#3,545 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
PHP
Stars
143
Forks
191
Avg merge
3d 12h
Merged PRs (30d)
9

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Neos.Utility.ObjectHandling/Classes/ObjectAccess.php around lines 194-196 and inspect how initializePropertyGetterCache uses get_object_vars. Compare that behavior with the proposed ReflectionClass approach for public, uninitialized properties, then verify that validation can access both initialized and uninitialized public properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.