Skip to content

[DependencyInjection] Fixed variadic method parameter in autowired classes #21372

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
wants to merge 3 commits into from
Closed

[DependencyInjection] Fixed variadic method parameter in autowired classes #21372

wants to merge 3 commits into from

Conversation

brainexe
Copy link
Contributor

@brainexe brainexe commented Jan 22, 2017

Q A
Branch? 3.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets --
License MIT

Autowiring classes containing methods with variadic method parameter throws a ReflectionException in compile process:

PHP Fatal error:  Uncaught ReflectionException: Internal error: Failed to retrieve the default value in /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php:437
Stack trace:
#0 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(437): ReflectionParameter->getDefaultValue()
#1 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(80): Symfony\Component\DependencyInjection\Compiler\AutowirePass::getResourceMetadataForMethod(Object(ReflectionMethod))
#2 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(105): Symfony\Component\DependencyInjection\Compiler\AutowirePass::createResourceForClass(Object(ReflectionClass))
#3 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(48): Symfony\Component\DependencyInjection\Compiler\AutowirePass->completeDefinition('__controller.Sw...', Object(Symfony\Component\DependencyInjection\Definition), Array)
#4 /.../vendor/symfony/dependency-injection/Compiler/Compiler in /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php on line 437

Example:

<?php
class FooVariadic
{
    public function bar(...$arguments)
    {
    }
}

$method = new ReflectionMethod(FooVariadic::class, 'bar');
$parameter = $method->getParameters()[0];
$parameter->getDefaultValue(); // -> ReflectionException: Internal error: Failed to retrieve the default value in ...

…asses

ReflectionException: Internal error: Failed to retrieve the default value in /www/raspberry/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:437
public function testProcessVariadic()
{
$container = new ContainerBuilder();
$container->register('foo', __NAMESPACE__.'\Foo');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Foo::class here too

@dunglas
Copy link
Member

dunglas commented Jan 22, 2017

👍

@fabpot
Copy link
Member

fabpot commented Jan 22, 2017

Thank you @brainexe.

fabpot added a commit that referenced this pull request Jan 22, 2017
…utowired classes (brainexe)

This PR was squashed before being merged into the 3.1 branch (closes #21372).

Discussion
----------

[DependencyInjection] Fixed variadic method parameter in autowired classes

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | --
| License       | MIT

Autowiring classes containing methods with variadic method parameter throws a ReflectionException in compile process:

```
PHP Fatal error:  Uncaught ReflectionException: Internal error: Failed to retrieve the default value in /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php:437
Stack trace:
#0 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(437): ReflectionParameter->getDefaultValue()
#1 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(80): Symfony\Component\DependencyInjection\Compiler\AutowirePass::getResourceMetadataForMethod(Object(ReflectionMethod))
#2 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(105): Symfony\Component\DependencyInjection\Compiler\AutowirePass::createResourceForClass(Object(ReflectionClass))
#3 /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php(48): Symfony\Component\DependencyInjection\Compiler\AutowirePass->completeDefinition('__controller.Sw...', Object(Symfony\Component\DependencyInjection\Definition), Array)
#4 /.../vendor/symfony/dependency-injection/Compiler/Compiler in /.../vendor/symfony/dependency-injection/Compiler/AutowirePass.php on line 437
```

**Example:**
```
<?php
class FooVariadic
{
    public function bar(...$arguments)
    {
    }
}

$method = new ReflectionMethod(FooVariadic::class, 'bar');
$parameter = $method->getParameters()[0];
$parameter->getDefaultValue(); // -> ReflectionException: Internal error: Failed to retrieve the default value in ...
```

Commits
-------

a7f63de [DependencyInjection] Fixed variadic method parameter in autowired classes
@fabpot fabpot closed this Jan 22, 2017
fabpot added a commit that referenced this pull request Jan 23, 2017
…alidation secti… (davewwww)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle] add "mapping" configuration key at validation secti…

| Q | A |
| --- | --- |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #15655 |
| License | MIT |
| Doc PR | symfony/symfony-docs#7407 |

This feature allows you, to define additional validation files or directories which are not in the 'Bundle*/Resources/config/' directory.

``` yaml
#config.yml
framework:
  validation:
    mapping:
      paths:
        - "path/to/file/validation.yml"
        - "path/to/file/validation.xml"
        - "path/to/another/directory"
```

Commits
-------

d696cfb [FrameworkBundle] Configurable paths for validation files
60d7d43 fix merge
61475b5 Merge branch '3.2'
ba41e70 Merge branch '3.1' into 3.2
4268aba Merge branch '2.8' into 3.1
3faf655 Merge branch '2.7' into 2.8
e95fc09 fix getMock usage
482828c fix merge
ed5eb6d bug #21372 [DependencyInjection] Fixed variadic method parameter in autowired classes (brainexe)
a7f63de [DependencyInjection] Fixed variadic method parameter in autowired classes
9ef4271 minor #21371 [Validator] update German translation (xabbuh)
f920e61 update German translation
41c72ab minor #21335 [Validator] Improved error message for missing upload_tmp_dir (Breuls)
afbf227 [Validator] Improved error message for missing upload_tmp_dir
@fabpot fabpot mentioned this pull request Jan 28, 2017
@fabpot fabpot mentioned this pull request Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants