Skip to content

Fix php_uname() ValueError on PHP 8.4+#125

Open
JoshSalway wants to merge 2 commits intolaravel:masterfrom
JoshSalway:fix/open-command-php-uname
Open

Fix php_uname() ValueError on PHP 8.4+#125
JoshSalway wants to merge 2 commits intolaravel:masterfrom
JoshSalway:fix/open-command-php-uname

Conversation

@JoshSalway
Copy link

@JoshSalway JoshSalway commented Mar 17, 2026

Fixes #106

Summary

OpenCommand passes PHP_OS (a string constant like "Darwin" or "Linux") as the mode parameter to php_uname():

$os = strtolower(php_uname(PHP_OS));

In PHP 8.4+, php_uname() strictly requires a single character mode ('a', 's', 'n', etc.), causing a ValueError. On PHP < 8.4, the multi-character string was silently accepted but produced undefined behavior (it only used the first character).

Since PHP_OS already contains the OS name (same value as php_uname('s')), the fix is to use it directly:

$os = strtolower(PHP_OS);

PHP_OS is a compile-time constant available since PHP 4, so this works on all supported versions (^8.1.0 per composer.json).

Tests

Added tests/Feature/OpenCommandTest.php with 3 tests:

  • it can open a site in the browser — integration test exercising the full command with mocks
  • it detects os without throwing value error — unit test confirming strtolower(PHP_OS) works without ValueError (the exact regression this PR fixes)
  • it correctly identifies the current platform — validates OS detection returns darwin/linux/other

All 3 tests pass.

Test plan

  • forge open works on macOS (PHP_OS = "Darwin")
  • forge open works on Linux (PHP_OS = "Linux")
  • Backwards compatible with PHP 8.1–8.3 (same runtime value as before)
  • Fixes ValueError on PHP 8.4+
  • Regression tests confirm fix

🤖 Generated with Claude Code

JoshSalway and others added 2 commits March 17, 2026 15:53
PHP_OS is a string constant (e.g. "Darwin"), not a valid single-character
mode for php_uname(). Use PHP_OS directly since it already contains
the OS name.

Fixes laravel#106

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verifies that the OS detection in OpenCommand works without throwing
a ValueError, confirming the php_uname() fix for PHP 8.4+.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

'forge open' - php_uname(): Argument #1 ($mode) must be a single character

1 participant