Skip to content

Studio: Add PHP 8.5 support and fix JSON parsing of WP-CLI output - #2551

Merged
epeicher merged 9 commits into
trunkfrom
update/php-8-5
Feb 11, 2026
Merged

Studio: Add PHP 8.5 support and fix JSON parsing of WP-CLI output#2551
epeicher merged 9 commits into
trunkfrom
update/php-8-5

Conversation

@epeicher

@epeicher epeicher commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

  • Added PHP 8.5 to the supported PHP versions list and set it as the latest supported version
  • Created parseJsonFromPhpOutput utility that extracts JSON from PHP output containing deprecation notices/warnings
  • Applied robust JSON parsing across all 5 WP-CLI JSON parsing call sites to handle PHP warnings in output

PHP 8.5 introduces a deprecation warning from WP-CLI's bundled react/promise package ("Case statements followed by a semicolon are deprecated"). This warning gets prepended to stdout, causing JSON.parse() to fail with "Unexpected token 'D'" when parsing WP-CLI JSON output.

Testing Instructions

  • Test WP-CLI commands that return JSON output with PHP 8.5 selected
  • Verify site operations (start, stop, import/export) work correctly with PHP 8.5
  • Test the export functionality to ensure database exports and default exports parse JSON correctly
  • Test chat functionality that uses WP-CLI commands

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@epeicher epeicher self-assigned this Feb 6, 2026
@epeicher
epeicher changed the base branch from trunk to fix/php-output-json-parsing February 6, 2026 18:20
Base automatically changed from fix/php-output-json-parsing to trunk February 9, 2026 09:00
PHP 8.5 introduces deprecation warnings (e.g., from WP-CLI's
react/promise) that get prepended to stdout, breaking JSON.parse().

- Add PHP 8.5 to supported versions list
- Silence deprecation warnings via error_reporting ini setting for
  standalone WP-CLI execution
- Add parseJsonFromPhpOutput utility that extracts JSON from output
  containing PHP warnings, used across all WP-CLI JSON parsing sites
The parseJsonFromPhpOutput utility handles deprecation warnings at the
parsing level, making the error_reporting ini changes redundant.
@epeicher
epeicher marked this pull request as ready for review February 11, 2026 14:40
@epeicher
epeicher requested review from a team and Copilot February 11, 2026 14:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds PHP 8.5 as a supported runtime and hardens WP‑CLI JSON parsing to tolerate PHP 8.5 deprecation/warning noise being prepended to stdout (which otherwise breaks JSON.parse).

Changes:

  • Add PHP 8.5 to SupportedPHPVersions and set LatestSupportedPHPVersion to 8.5.
  • Introduce parseJsonFromPhpOutput helper to extract/parse JSON from mixed PHP output.
  • Replace direct JSON.parse(stdout) usage with the new helper across WP‑CLI JSON parsing call sites (chat, site server, import/export).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
common/types/php-versions.ts Adds PHP 8.5 to supported versions and marks it as latest.
common/lib/php-output-parser.ts New utility for extracting JSON from stdout containing PHP warnings/notices.
src/stores/chat-slice.ts Uses the new parser for WP‑CLI JSON output in chat flows.
src/site-server.ts Uses the new parser for theme-details JSON parsing.
src/lib/import-export/export/exporters/default-exporter.ts Uses the new parser when fetching plugins/themes JSON during export.
src/lib/import-export/export/export-database.ts Uses the new parser for sqlite tables --format=json output.

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

Comment thread common/lib/php-output-parser.ts Outdated
Comment thread common/lib/php-output-parser.ts
Default to any to match JSON.parse behavior; callers can narrow
via the generic parameter when needed.
The any default intentionally matches JSON.parse behavior.
@wpmobilebot

wpmobilebot commented Feb 11, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 87d0bd1 vs trunk

site-editor

Metric trunk 87d0bd1 Diff Change
load 2707.00 ms 2737.00 ms +30.00 ms ⚪ 0.0%

site-startup

Metric trunk 87d0bd1 Diff Change
siteCreation 7079.00 ms 7095.00 ms +16.00 ms ⚪ 0.0%
siteStartup 3923.00 ms 3931.00 ms +8.00 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was able to create a new site using PHP 8.5, I didn't spot any regression on that site.

Let’s add an entry to RELEASE-NOTES.txt to inform users that this new PHP version is now available.

Image

I see one unit test failing.

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function parseJsonFromPhpOutput< T = any >( output: string ): T {
const objectStart = output.indexOf( '{' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you think about trying to parse the response first and then fallback into the custom parse if it fails?

Suggested change
const objectStart = output.indexOf( '{' );
try {
return JSON.parse( output );
} catch {
// Fall through to extract JSON from mixed output
}
const objectStart = output.indexOf( '{' );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like that approach! I have updated it as part of 0212789. That will also include a better error message in case of non JSON detected

@epeicher
epeicher merged commit db31836 into trunk Feb 11, 2026
9 checks passed
@epeicher
epeicher deleted the update/php-8-5 branch February 11, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants