Skip to content

Fix PHP 8+ deprecation warnings breaking JSON parsing#72

Open
Swahjak wants to merge 1 commit intomoetelo:masterfrom
toppynl:fix/deprecations-cause-crash
Open

Fix PHP 8+ deprecation warnings breaking JSON parsing#72
Swahjak wants to merge 1 commit intomoetelo:masterfrom
toppynl:fix/deprecations-cause-crash

Conversation

@Swahjak
Copy link

@Swahjak Swahjak commented Jan 6, 2026

Summary

  • Pass -d display_errors=stderr to PHP executable when invoking commands
  • This redirects deprecation warnings to stderr, keeping stdout clean for JSON output

Problem

Since PHP 8.0, the default error_reporting includes E_DEPRECATED, causing deprecation notices to be output to stdout. This pollutes the JSON output from commands like bin/console debug:twig --format json, breaking the language server's JSON parsing.

Fixes #69

Approach

As suggested by @moetelo in #71, this uses PHP's -d flag to set display_errors=stderr at runtime. This ensures errors are redirected before any PHP code executes, making it effective even when deprecations occur in early bootstrap code (e.g., before Craft CMS can suppress them).

This approach is preferable to stripping text before JSON (as proposed in #71) because:

  1. It's more robust - no risk of deprecation messages containing { or [ characters
  2. It works at the PHP runtime level, before any application code runs
  3. The language server controls its own PHP invocation, so it's not affected by user environment constraints (DDEV/Docker)

Test plan

  • Test with PHP 8.4 and a project that triggers deprecation warnings
  • Verify JSON parsing works correctly with deprecations present

Pass `-d display_errors=stderr` to PHP executable to redirect
deprecation warnings to stderr, keeping stdout clean for JSON output.

Since PHP 8.0, the default error_reporting includes E_DEPRECATED,
causing deprecation notices to pollute stdout and break JSON parsing
in the language server.
@Swahjak Swahjak force-pushed the fix/deprecations-cause-crash branch from 7a9f273 to 01767fa Compare January 6, 2026 12:24
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.

Twiggy Language crashes when there are deprecated features.

1 participant