Skip to content

fix(legacy): ignore host php.ini when invoking embedded PHP#63

Merged
miguelsanchez-upsun merged 3 commits intomainfrom
library-loading-lando
May 4, 2026
Merged

fix(legacy): ignore host php.ini when invoking embedded PHP#63
miguelsanchez-upsun merged 3 commits intomainfrom
library-loading-lando

Conversation

@pjcdawkins
Copy link
Copy Markdown
Contributor

@pjcdawkins pjcdawkins commented May 1, 2026

Summary

When the CLI runs inside an environment that ships its own PHP configuration (for example Lando containers, where PHPRC or /usr/local/etc/php/ references extensions like pdo_mysql, opcache, bcmath, etc.), the embedded static PHP binary emitted a startup warning per extension before every command:

Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /lib/php/extensions/no-debug-non-zts-20240924/pdo_mysql (Dynamic loading not supported), /lib/php/extensions/no-debug-non-zts-20240924/pdo_mysql.so (Dynamic loading not supported)) in Unknown on line 0

The static binary has every extension the legacy CLI uses (curl, filter, openssl, pcntl, phar, posix, zlib) compiled in and cannot dlopen shared extensions, so any host php.ini is both useless and noisy.

This regressed when the CLI moved to externally built static PHP binaries; the previous packaging happened to avoid the system search paths.

Fix

Pass -n to the embedded PHP binary in makeCmd. -n tells PHP to skip the main php.ini and the scan directory entirely, regardless of PHPRC / PHP_INI_SCAN_DIR. The existing -d settings (openssl.cafile on Windows) still apply because they are command-line arguments.

There is no equivalent build-time option in static-php-cli: --with-config-file-path and --with-config-file-scan-dir only change defaults, and PHPRC / PHP_INI_SCAN_DIR always override them at runtime.

Tests

  • New unit test pinning -n in the args produced by makeCmd.
  • Extended TestLegacyCLI to point PHPRC and PHP_INI_SCAN_DIR at an ini that references extensions the static binary cannot load, then asserts no "Unable to load dynamic library" warnings appear in stdout or stderr. Verified to fail without -n and pass with it.

🤖 Generated with Claude Code

Pass -n to the embedded PHP binary so it skips any system php.ini and
scan directory. The static binary has every extension the legacy CLI
needs compiled in, and cannot dlopen shared extensions referenced by a
host php.ini. Without -n, environments that ship their own PHP config
(such as Lando containers, where PHPRC or /usr/local/etc/php points at
an ini listing pdo_mysql, opcache, bcmath, etc.) emit a "Unable to load
dynamic library ... Dynamic loading not supported" warning per
extension before every command.

Add a regression test that points PHPRC at an ini referencing such
extensions and asserts no startup warnings appear in either stdout or
stderr.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 1, 2026 21:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the legacy CLI wrapper’s embedded PHP invocation to avoid loading host php.ini files, preventing noisy startup warnings from extension directives that a static PHP binary cannot dlopen.

Changes:

  • Pass -n when invoking the embedded PHP binary to ignore host php.ini and scan directories.
  • Add a unit test to pin -n ordering in the args produced by makeCmd.
  • Extend TestLegacyCLI to verify no startup warnings are emitted even when PHPRC / PHP_INI_SCAN_DIR reference extension-loading ini contents.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/legacy/legacy.go Adds -n to embedded PHP command args so host PHP configuration is ignored.
internal/legacy/legacy_test.go Adds/extends tests to assert -n is present and that startup warnings are suppressed under hostile host ini env vars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/legacy/legacy_test.go
Set an EnvPrefix on the test wrapper so pharPath() does not read an
unprefixed PHAR_PATH from the host or CI environment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@miguelsanchez-upsun miguelsanchez-upsun merged commit 1fd0161 into main May 4, 2026
4 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.

3 participants