8000 [HttpKernel] TypeError in FileLinkFormatter for empty xdebug.file_link_format · Issue #45272 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[HttpKernel] TypeError in FileLinkFormatter for empty xdebug.file_link_format #45272
Closed
@mttsch

Description

@mttsch

Symfony version(s) affected

6.0

Description

With this change in 6.0, the previously untyped FileLinkFormatter::$fileLinkFormat property now does not support strings anymore. As the default value of the constructor parameter $fileLinkFormat is null and FileLinkFormatter::FORMATS does not have an entry for null, after this line

$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');

$fileLinkFormat will be an empty string if xdebug.file_link_format is empty, which appears to be its default value. Thus,

if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);
}

is never entered and

$this->fileLinkFormat = $fileLinkFormat;

throws a TypeError because a string is assigned to an array|false variable.

How to reproduce

  1. Setup PHP with an empty xdebug.file_link_format value:
$ php -i | grep xdebug.file_link_format
xdebug.file_link_format => no value => no value
  1. Install symfony with webapp (as instructed in the documentation):
composer create-project symfony/skeleton . 6.0.99 && composer require webapp

(I added the explicit version number because I was also testing previous versions where the issue did not occur.)

  1. You get the following exception:
!!  TypeError {#4981
!!    #message: "Cannot assign string to property Symfony\Component\HttpKernel\Debug\FileLinkFormatter::$fileLinkFormat of type array|false"
!!    #code: 0
!!    #file: "./vendor/symfony/http-kernel/Debug/FileLinkFormatter.php"
!!    #line: 53
!!    trace: {
!!      ./vendor/symfony/http-kernel/Debug/FileLinkFormatter.php:53 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:1236 {
!!        ContainerQqKtafO\App_KernelDevDebugContainer->getDebug_FileLinkFormatterService()
!!        ›         return ($this->privates['debug.file_link_formatter.url_format'] ?? $this->load('getDebug_FileLinkFormatter_UrlFormatService'));
!!        ›     });
!!        › }
!!      }
!!      ./var/cache/dev/ContainerQqKtafO/getVarDumper_ContextualizedCliDumper_InnerService.php:22 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:429 { …}
!!      ./var/cache/dev/ContainerQqKtafO/getDebug_DumpListenerService.php:23 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:429 { …}
!!      ./var/cache/dev/ContainerQqKtafO/App_KernelDevDebugContainer.php:825 { …}
!!      ./vendor/symfony/event-dispatcher/EventDispatcher.php:245 { …}
!!      ./vendor/symfony/event-dispatcher/EventDispatcher.php:76 { …}
!!      ./vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:283 { …}
!!      ./vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:146 { …}
!!      ./vendor/symfony/console/Application.php:1004 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:94 { …}
!!      ./vendor/symfony/console/Application.php:299 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:80 { …}
!!      ./vendor/symfony/console/Application.php:171 { …}
!!      ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54 { …}
!!      ./vendor/autoload_runtime.php:29 { …}
!!      ./bin/console:11 { …}
!!    }
!!  }

Possible Solution

Properly handle the case of $fileLinkFormat being an empty string by setting FileLinkFormatter::$fileLinkFormat to false.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0