Repository: symfony/symfony
File: src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php (PHP)

Code before:

    public function load(mixed $resource, ?string $type = null): mixed
    {
        // the container and loader variables are exposed to the included file below
        $container = $this->container;
        $loader = $this;

        $path = $this->locator->locate($resource);
        $this->setCurrentDir(\dirname($path));
        $this->container->fileExists($path);

        // Force load ContainerConfigurator to make env(), param() etc available.
        class_exists(ContainerConfigurator::class);

        $autoloaderRegistered = false;
        if (null === self::$configBuilderAutoloader) {
            $generator = $this->generator;
            self::$configBuilderAutoloader = function (string $class) use ($loader, $generator) {
                if (!$generator || !str_starts_with($class, 'Symfony\\Config\\') || !str_ends_with($class, 'Config')) {
                    return;
                }

                try {
                    $loader->configBuilder($class);
                } catch (\LogicException|\InvalidArgumentException) {
                    // no-op
                }
            };
            spl_autoload_register(self::$configBuilderAutoloader);
            $autoloaderRegistered = true;
        }

        // the closure forbids access to the private scope in the included file
        $load = \Closure::bind(static function ($path, $env) use ($container, $loader, $resource, $type) {
            return include $path;
        }, null, null);

        try {
            try {
                if (1 === $result = $load($path, $this->env)) {
                    $result = null;
                }
            } catch (\Error $e) {
                $load = \Closure::bind(function ($path, $env) use ($container, $loader, $resource, $type) {
                    return include $path;
                }, $this, ProtectedPhpFileLoader::class);

                if (1 === $result = $load($path, $this->env)) {
                    $result = null;
                }


Review comment (bug):
Do you know which error can be hidden here? Hiding generic exceptions like this can make debugging complicated.

Note that `InvalidArgumentException` extends `LogicException`, so it can be removed.

Code after:

    public function load(mixed $resource, ?string $type = null): mixed
    {
        // the container and loader variables are exposed to the included file below
        $container = $this->container;
        $loader = $this;

        $path = $this->locator->locate($resource);
        $this->setCurrentDir(\dirname($path));
        $this->container->fileExists($path);

        // Force load ContainerConfigurator to make env(), param() etc available.
        class_exists(ContainerConfigurator::class);

        if ($autoloaderRegistered = !$this->configBuilderAutoloader && $this->generator) {
            spl_autoload_register($this->configBuilderAutoloader = function (string $class) {
                if (str_starts_with($class, 'Symfony\\Config\\') && str_ends_with($class, 'Config')) {
                    $this->configBuilder($class);
                }
            });
        }

        // the closure forbids access to the private scope in the included file
        $load = \Closure::bind(static function ($path, $env) use ($container, $loader, $resource, $type) {
            return include $path;
        }, null, null);

        try {
            try {
                if (1 === $result = $load($path, $this->env)) {
                    $result = null;
                }
            } catch (\Error $e) {
                $load = \Closure::bind(function ($path, $env) use ($container, $loader, $resource, $type) {
                    return include $path;
                }, $this, ProtectedPhpFileLoader::class);

                if (1 === $result = $load($path, $this->env)) {
                    $result = null;
                }

                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());
            }

            if (\is_object($result) && \is_callable($result)) {
                $result = $this->callConfigurator($result, new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource, $this->env), $path);
            }
            if ($result instanceof ConfigBuilderInterface) {
                $this->loadExtensionConfig($result->getExtensionAlias(), ContainerConfigurator::processValue($result->toArray()), $path);
            } elseif (is_iterable($result)) {
                foreach ($result as $key => $config) {