Skip to content
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

PHP 8.0: CompiledContainer Mangling Named Parameters into Namespaced Ones #787

Open
BusterNeece opened this issue Jun 28, 2021 · 5 comments
Labels

Comments

@BusterNeece
Copy link

Hello! I'm using PHP-DI 6.3.4 and we're in the process of updating our app to make better use of new PHP 8.0 best practices. I discovered when including the following code in my service definition:

Symfony\Contracts\Cache\CacheInterface::class => function (
        App\Environment $environment,
        Psr\Log\LoggerInterface $logger,
    ) {
            $tempDir = $environment->getTempDirectory() . DIRECTORY_SEPARATOR . 'cache';
            $cacheInterface = new Symfony\Component\Cache\Adapter\FilesystemAdapter(
               directory: $tempDir
            );

        $cacheInterface->setLogger($logger);
        return $cacheInterface;
    },

...that the compiled container yielded this result:

 protected function get9()
    {
        return $this->resolveFactory(static function (
        \App\Environment $environment,
        \Psr\Log\LoggerInterface $logger
    ) {
          $tempDir = $environment->getTempDirectory() . DIRECTORY_SEPARATOR . 'cache';
          $cacheInterface = new \Symfony\Component\Cache\Adapter\FilesystemAdapter(
              \directory: $tempDir
          );

        $cacheInterface->setLogger($logger);
        return $cacheInterface;
    }, 'Symfony\\Contracts\\Cache\\CacheInterface');
    }

This yields the error:

Parse error: syntax error, unexpected token ":", expecting ")" in CompiledContainer.php on line 228

Presumably this is because it's detecting the named method argument as something it should be namespacing, which is causing parsing errors down the line.

@mnapoli mnapoli added the bug label Jun 28, 2021
@mnapoli
Copy link
Member

mnapoli commented Jun 28, 2021

Hi, thanks for the report! It seems to be caused by opis/closure#90 and unfortunately I don't see any pull request to support that yet in opis/closure.

@BusterNeece
Copy link
Author

@mnapoli looking into that issue, it looks like they did actually merge a fix for it into their 4.x branch, which is intended to support the new PHP 8.x features like this one.

Is that 4.x branch already in use on the beta branch of PHP-DI? I wouldn't have any issue switching over to that for now.

@mnapoli
Copy link
Member

mnapoli commented Jul 5, 2021

No currently PHP-DI uses v3. Maybe it could be possible to support v3 and v4 if they haven't changed the API that PHP-DI uses?

@BusterNeece
Copy link
Author

@mnapoli I'm worried that may be the only way to actually take advantage of PHP 8.0-level features inside the closures that are compiled, since they've closed PRs that would add PHP 8.0 functionality to 3.x, saying those features were reserved exclusively for 4.x.

The problem, though, is that 4.x seems to require the php-ffi extension be installed. That would be a huge BC break and is a pretty significant roadblock to jumping to that version.

@mnapoli
Copy link
Member

mnapoli commented Jul 5, 2021

Oh… yeah very good point, thanks for bringing that up.

I've asked for some clarification in opis/closure#59 (comment) as I see Laravel is also using opis/closure.

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

No branches or pull requests

2 participants