Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] fix regression when extending the Container class without a constructor #26427

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions 10 src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,13 @@ public function __construct()
if ($this->container->isCompiled()) {
if (Container::class !== $baseClassWithNamespace) {
$r = $this->container->getReflectionClass($baseClassWithNamespace, false);

if (null !== $r && (null !== $constructor = $r->getConstructor()) && 0 === $constructor->getNumberOfRequiredParameters()) {
$code .= " parent::__construct();\n\n";
if (null !== $r
&& (null !== $constructor = $r->getConstructor())
&& 0 === $constructor->getNumberOfRequiredParameters()
&& Container::class !== $constructor->getDeclaringClass()->name
) {
$code .= " parent::__construct();\n";
$code .= " \$this->parameterBag = null;\n\n";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;

class NoConstructorContainer
use Symfony\Component\DependencyInjection\Container;

class NoConstructorContainer extends Container
Copy link
Member

Choose a reason for hiding this comment

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

Should we create a new test case to still keep the existing one (a class without a constructor not inheriting one from its base class)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was also thinking about that .. and to me the old test just seemed incomplete since that class didn't even implement the interface.

{
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
public function __construct()
{
parent::__construct();
$this->parameterBag = null;

$this->services = array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
public function __construct()
{
parent::__construct();
$this->parameterBag = null;

$this->services = array();

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.