10000 [DependencyInjection] WeakReference on 6.3 cause error · Issue #50439 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] WeakReference on 6.3 cause error #50439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HypeMC opened this issue May 25, 2023 · 0 comments
Closed

[DependencyInjection] WeakReference on 6.3 cause error #50439

HypeMC opened this issue May 25, 2023 · 0 comments

Comments

@HypeMC
Copy link
Member
HypeMC commented May 25, 2023

Symfony version(s) affected

6.3.x

Description

After upgrading my application to version 6.3.0-RC1 I started getting the following error on my CI pipeline:

Error: Attempt to modify property "privates" on null

After some research I found out the problem was introduced in #48469 .

How to reproduce

Here's an example test:

use App\Factory\PostFactory;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;

class ExampleTest extends KernelTestCase
{
    use Factories;
    use ResetDatabase;

    public function testSomething(): void
    {
        gc_collect_cycles();

        $posts = PostFactory::createMany(5);

        self::assertCount(5, $posts);
    }
}

It would fail on the CI pipeline, but would pass locally. After a while I've realized I was able to reproduce the problem locally by adding gc_collect_cycles(); (this was not required for the test to fail on the CI).

I was also able to reproduce the problem with the following test:

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Reference;

class ContainerTest extends KernelTestCase
{
    public function testWeakReferenceWithRewindableGenerator()
    {
        $container = new ContainerBuilder();
        $container->register('bar', \stdClass::class);
        $container->register('baz', \stdClass::class);
        $container->register('foo', \stdClass::class)
            ->setPublic(true)
            ->setProperty('iterator', new IteratorArgument([
                'bar' => new Reference('bar'),
                'baz' => new Reference('baz'),
            ]))
        ;
        $container->compile();

        $dumper = new PhpDumper($container);
        eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_WeakReferenceWithRewindableGenerator']));

        $container = new \Symfony_DI_PhpDumper_Test_WeakReferenceWithRewindableGenerator();

        $foo = $container->get('foo');
        self::assertInstanceOf(RewindableGenerator::class, $foo->iterator);

        unset($container);

        $array = iterator_to_array($foo->iterator); // Error: Attempt to modify property "privates" on null
        self::assertCount(2, $array);
        self::assertArrayHasKey('bar', $array);
        self::assertInstanceOf(\stdClass::class, $array['bar']);
        self::assertArrayHasKey('baz', $array);
        self::assertInstanceOf(\stdClass::class, $array['baz']);
    }
}

reproducer.zip

Possible Solution

No response

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0