neos / neos/flow-development-collection

Serialization of Objects in statically compiled methods searches in namespace

Open
#2,001 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When a method that uses @Flow\CompileStatic returns an instance of anything, then when trying to re-hydrate the object at runtime the object is searched for in the current namespace instead of starting at the root namespace.

Steps to Reproduce
  1. Have a statically compiled method in a namespaced class (e.g. namespace Foo\Bar\Baz)
  2. Return an instance of something from that method ( e.g. return new \DateTime() )
  3. Run in Production mode

Minimal example:

namespace Foo\Bar\Baz;
use Neos\Flow\Annotations as Flow;

class Reproduction {
    /** @Flow\CompileStatic */
    public static staticallyCompiledMethod($objectManager) {
        return new \DateTime();
    }
}
Expected behavior

The correct class (in this case \DateTime) gets rehydrated.

Actual behavior

The class to re-hydrate is being searched in the current namespace (in this case Foo\Bar\Baz\DateTime because the compiled code looks something like the following:

namespace Foo\Bar\Baz;

// [...]
public static staticallyCompiledMethod($objectManager) {
    return DateTime::__set_state(/* ... */);
}

This behavior is actually mentioned in a small sentence in the PHP manual for var_export:

Warning
When var_export() exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility.

In a quick research I could not find a way of convincing var_export to add leading slashes.

For quicker lookup: ProxyClassBuilder::compileStaticMethods is where the code is generated:
https://github.com/neos/flow-development-collection/blob/master/Neos.Flow/Classes/ObjectManagement/DependencyInjection/ProxyClassBuilder.php#L683

Affected Versions

Neos: 4.3.12
Flow: 5.3.14

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.Flow/Classes/ObjectManagement/DependencyInjection/ProxyClassBuilder.php at ProxyClassBuilder::compileStaticMethods, then reproduce the namespaced @Flow\CompileStatic case in production mode. Verify that an object such as \DateTime is rehydrated from the root namespace rather than the current namespace, using the provided minimal example as the completion check.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.