Skip to content

[Process] (Unwanted?) BC break with strict typing #28609

Closed
@soullivaneuh

Description

@soullivaneuh

Symfony version(s) affected: 4.1.4

Description

If you create a process with an array command-line containing null variable, it will fail:

Fatal error: Uncaught TypeError: Argument 1 passed to Symfony\Component\Process\Process::escapeArgument() must be of the type string, null given in /code/vendor/symfony/process/Process.php:1533
Stack trace:
#0 [internal function]: Symfony\Component\Process\Process->escapeArgument(NULL)
#1 /code/vendor/symfony/process/Process.php(262): array_map(Array, Array)
#2 /code/vendor/symfony/process/Process.php(200): Symfony\Component\Process\Process->start(NULL, Array)
#3 /code/test.php(13): Symfony\Component\Process\Process->run()
#4 {main}

How to reproduce

<?php

declare(strict_types=1);

require_once __DIR__.'/src/autoload.php';

$process = new \Symfony\Component\Process\Process([
    'ls -la',
    'test',
    null,
    'something',
]);
$process->run();

Possible Solution

I know it's a new major, but I found nothing about this issue on the upgrade guide. Plus, the error is not very explicit.

Two possibility:

  1. Cast all null parameter to string before using escapeArgument to have the same behavior as Symfony 3.
  2. Complete the upgrade guide and prevent the error by a more explicit one.

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