Skip to content

Commit bc4567f

Browse files
committed
remove ability to access $this and the loader's internal state
1 parent 41cd2ca commit bc4567f

File tree

3 files changed

+3
-28
lines changed

3 files changed

+3
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
8.0
55
---
66

7+
* Remove support for using `$this` or the loader's internal scope from PHP config files; use the `$loader` variable instead
78
* Remove `ExtensionInterface::getXsdValidationBasePath()` and `getNamespace()` without alternatives, the XML configuration format is no longer supported
89
* Add argument `$throwOnAbstract` to `ContainerBuilder::findTaggedResourceIds()`
910
* Registering a service without a class when its id is a non-existing FQCN throws an error

Loader/PhpFileLoader.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,8 @@ class_exists(ContainerConfigurator::class);
7575
}, null, null);
7676

7777
try {
78-
try {
79-
if (1 === $result = $load($path, $this->env)) {
80-
$result = null;
81-
}
82-
} catch (\Error $e) {
83-
$load = \Closure::bind(function ($path, $env) use ($container, $loader, $resource, $type) {
84-
return include $path;
85-
}, $this, ProtectedPhpFileLoader::class);
86-
87-
if (1 === $result = $load($path, $this->env)) {
88-
$result = null;
89-
}
90-
91-
trigger_deprecation('symfony/dependency-injection', '8.1', 'Using `$this` or its internal scope in config files is deprecated, use the `$loader` variable instead in "%s" on line %d.', $e->getFile(), $e->getLine());
78+
if (1 === $result = $load($path, $this->env)) {
79+
$result = null;
9280
}
9381

9482
if (\is_object($result) && \is_callable($result)) {

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
require_once __DIR__.'/../Fixtures/includes/fixture_app_services.php';
1616

1717
use PHPUnit\Framework\Attributes\DataProvider;
18-
use PHPUnit\Framework\Attributes\Group;
19-
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
2018
use PHPUnit\Framework\TestCase;
2119
use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
2220
use Symfony\Component\Config\FileLocator;
@@ -368,16 +366,4 @@ public function testReturnsGenerator()
368366
$loader->load('return_generator.php');
369367
$this->assertSame([['color' => 'red']], $container->getExtensionConfig('acme'));
370368
}
371-
372-
#[IgnoreDeprecations]
373-
#[Group('legacy')]
374-
public function testTriggersDeprecationWhenAccessingLoaderInternalScope()
375-
{
376-
$fixtures = realpath(__DIR__.'/../Fixtures');
377-
$loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator($fixtures.'/config'));
378-
379-
$this->expectUserDeprecationMessageMatches('{^Since symfony/dependency-injection 8.1: Using \`\$this\` or its internal scope in config files is deprecated, use the \`\$loader\` variable instead in ".+" on line \d+\.$}');
380-
381-
$loader->load('legacy_internal_scope.php');
382-
}
383369
}

0 commit comments

Comments
 (0)