Skip to content

Fix PhpHelpers::checkCode crash when PHP binary path contains spaces#415

Merged
dg merged 9 commits intonette:masterfrom
davidkvasnovsky:fix/php-binary-space-in-path
Apr 9, 2026
Merged

Fix PhpHelpers::checkCode crash when PHP binary path contains spaces#415
dg merged 9 commits intonette:masterfrom
davidkvasnovsky:fix/php-binary-space-in-path

Conversation

@davidkvasnovsky
Copy link
Copy Markdown
Contributor

Problem

PhpHelpers::checkCode passes the PHP binary path to proc_open as a concatenated string:

$phpBinary . ' -l -n'

On macOS with Laravel Herd, PHP_BINARY resolves to a path containing spaces:

/Users/.../Library/Application Support/Herd/bin/php84

The shell splits this at the space, resulting in exit code 127 (No such file or directory), empty stdout, and then a crash at line 271:

Warning: Undefined array key 1 in PhpHelpers.php on line 271
Fatal error: strip_tags(): Argument #1 ($string) must be of type string, null given

This affects the Latte linter (Latte\Tools\Linter) which enables the PHP linter via enablePhpLinter(PHP_BINARY).

Fix

Pass an array to proc_open instead of a string. This bypasses the shell entirely, avoiding word-splitting. This is also what the existing bypass_shell option was intended to do, but that only works on Windows — the array form works on all platforms.

-$phpBinary . ' -l -n',
+[$phpBinary, '-l', '-n'],

dg and others added 8 commits April 7, 2026 09:07
proc_open with a string command goes through the shell, which splits
the path at spaces. This breaks on macOS with Laravel Herd where
PHP_BINARY is e.g. /Users/.../Application Support/Herd/bin/php84.

Using an array bypasses the shell entirely, which is also what the
existing bypass_shell option was intended to do (but only works on
Windows).
@dg dg force-pushed the master branch 3 times, most recently from 9ae546d to 1c83b08 Compare April 9, 2026 15:22
@dg
Copy link
Copy Markdown
Member

dg commented Apr 9, 2026

thanks

@dg dg merged commit be1cd2f into nette:master Apr 9, 2026
dg pushed a commit that referenced this pull request Apr 9, 2026
#415)

proc_open with a string command goes through the shell, which splits
the path at spaces. This breaks on macOS with Laravel Herd where
PHP_BINARY is e.g. /Users/.../Application Support/Herd/bin/php84.

Using an array bypasses the shell entirely, which is also what the
existing bypass_shell option was intended to do (but only works on
Windows).
dg pushed a commit that referenced this pull request Apr 22, 2026
#415)

proc_open with a string command goes through the shell, which splits
the path at spaces. This breaks on macOS with Laravel Herd where
PHP_BINARY is e.g. /Users/.../Application Support/Herd/bin/php84.

Using an array bypasses the shell entirely, which is also what the
existing bypass_shell option was intended to do (but only works on
Windows).
dg pushed a commit that referenced this pull request Apr 22, 2026
#415)

proc_open with a string command goes through the shell, which splits
the path at spaces. This breaks on macOS with Laravel Herd where
PHP_BINARY is e.g. /Users/.../Application Support/Herd/bin/php84.

Using an array bypasses the shell entirely, which is also what the
existing bypass_shell option was intended to do (but only works on
Windows).
dg pushed a commit that referenced this pull request Apr 22, 2026
…nary path (#415)

proc_open with a string command goes through the shell, which splits
the path at spaces. Using an array bypasses the shell entirely,
which is also what the existing bypass_shell option was intended to do.
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