Studio: Add PHP 8.5 support and fix JSON parsing of WP-CLI output - #2551
Conversation
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
6833768 to
7c73359
Compare
The parseJsonFromPhpOutput utility handles deprecation warnings at the parsing level, making the error_reporting ini changes redundant.
There was a problem hiding this comment.
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.5toSupportedPHPVersionsand setLatestSupportedPHPVersionto8.5. - Introduce
parseJsonFromPhpOutputhelper 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.
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.
📊 Performance Test ResultsComparing 87d0bd1 vs trunk site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
| */ | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export function parseJsonFromPhpOutput< T = any >( output: string ): T { | ||
| const objectStart = output.indexOf( '{' ); |
There was a problem hiding this comment.
What do you think about trying to parse the response first and then fallback into the custom parse if it fails?
| const objectStart = output.indexOf( '{' ); | |
| try { | |
| return JSON.parse( output ); | |
| } catch { | |
| // Fall through to extract JSON from mixed output | |
| } | |
| const objectStart = output.indexOf( '{' ); |
There was a problem hiding this comment.
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
Avoids unnecessary string scanning in the common case where output is clean JSON.

Related issues
Proposed Changes
parseJsonFromPhpOutpututility that extracts JSON from PHP output containing deprecation notices/warningsPHP 8.5 introduces a deprecation warning from WP-CLI's bundled
react/promisepackage ("Case statements followed by a semicolon are deprecated"). This warning gets prepended to stdout, causingJSON.parse()to fail with "Unexpected token 'D'" when parsing WP-CLI JSON output.Testing Instructions
Pre-merge Checklist