Skip to content

[13.x] Preserve falsey concurrency exception parameters#60822

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
Amirhf1:fix-concurrency-falsey-exception-parameters
Jul 17, 2026
Merged

[13.x] Preserve falsey concurrency exception parameters#60822
taylorotwell merged 1 commit into
laravel:13.xfrom
Amirhf1:fix-concurrency-falsey-exception-parameters

Conversation

@Amirhf1

@Amirhf1 Amirhf1 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The Problem

When a concurrent task fails while using the ProcessDriver, the framework captures the exception in the child process, serializes it, and reconstructs it in the parent process.

However, during the reconstruction process in ProcessDriver.php, the driver uses array_filter() without a callback to check if custom constructor parameters were captured:

...(! empty(array_filter($result['parameters']))
    ? $result['parameters']
    : [$result['message']])

Because PHP's default array_filter strips out all falsey values, legitimate arguments like 0, false, or "" (empty string) are treated as completely absent. As a result, the framework incorrectly falls back to passing the exception's string message into the constructor instead of the actual arguments.

If you throw a custom exception that expects a falsey integer or boolean value:

class RetryAfterException extends Exception
{
    public function __construct(public int $seconds)
    {
        parent::__construct("Retry after {$seconds} seconds.");
    }
}

Concurrency::run([
    fn () => throw new RetryAfterException(0),
]);

The 0 parameter is discarded because it's falsey. When the driver attempts to reconstruct the exception, it passes the string message into the constructor instead of the integer 0, which immediately crashes the application with a TypeError.

After this PR

The reconstructed exception faithfully retains its original constructor parameters:

// Works perfectly now:
$exception->seconds; // 0

The presence check now explicitly filters out only null values. Valid non-falsey parameters remain unaffected, and the message fallback still cleanly handles cases where no constructor parameters could be captured at all.

@taylorotwell
taylorotwell merged commit 89d5f0a into laravel:13.x Jul 17, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants