Skip to content

XML-RPC: Use instanceof instead of is_a() in IXR. - #15203

Closed
dhrupo wants to merge 8 commits into
WordPress:trunkfrom
dhrupo:php86-ixr-is-a
Closed

dhrupo wants to merge 8 commits into
WordPress:trunkfrom
dhrupo:php86-ixr-is-a

Conversation

@dhrupo

@dhrupo dhrupo commented Oct 30, 2026

Copy link
Copy Markdown

PHP 8.6 deprecates calling is_a() with a string when $allow_string is false. IXR_Server checks method results, which are often strings, with is_a( $result, 'IXR_Error' ), and IXR_IntrospectionServer does the same for date arguments. This uses instanceof, which gives the same result without the deprecation.

Testing

  • trunk, PHP 8.6.0-dev: --group xmlrpc has 4 errors (the Tests_XMLRPC_Basic::test_multicall_* tests, "Calling is_a() with a string when $allow_string is false").
  • this branch: OK (368 tests, 1383 assertions) on PHP 7.4.33, 8.5.12 and 8.6.0-dev.

Trac ticket: https://core.trac.wordpress.org/ticket/66418

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the issue by running the test suite on PHP 8.6, writing the change and running the checks above. I reviewed the change and checked the results myself.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

PHP 8.6 deprecates calling `is_a()` with a string when `$allow_string` is false. `IXR_Server` checks method results, which are often strings, with `is_a( $result, 'IXR_Error' )`, and `IXR_IntrospectionServer` does the same for `date` arguments. `instanceof` gives the same result without the deprecation.

Props dhrupo.
Fixes #66418.
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dhrupo, westonruter, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@westonruter westonruter 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.

For a PHP 8.6 run on trunk, I do see the these errors:

17) Tests_XMLRPC_Basic::test_multicall_with_non_array_params
Calling is_a() with a string when $allow_string is false

/var/www/src/wp-includes/IXR/class-IXR-server.php:237
/var/www/tests/phpunit/tests/xmlrpc/basic.php:181

18) Tests_XMLRPC_Basic::test_multicall_with_missing_params
Calling is_a() with a string when $allow_string is false

/var/www/src/wp-includes/IXR/class-IXR-server.php:237
/var/www/tests/phpunit/tests/xmlrpc/basic.php:245

19) Tests_XMLRPC_Basic::test_multicall_with_non_struct_entry
Calling is_a() with a string when $allow_string is false

/var/www/src/wp-includes/IXR/class-IXR-server.php:237
/var/www/tests/phpunit/tests/xmlrpc/basic.php:282

20) Tests_XMLRPC_Basic::test_multicall_with_missing_method_name
Calling is_a() with a string when $allow_string is false

/var/www/src/wp-includes/IXR/class-IXR-server.php:237
/var/www/tests/phpunit/tests/xmlrpc/basic.php:309

These are fixed in the corresponding run on this branch.

westonruter and others added 2 commits October 30, 2026 13:47
Replace the `is_object() && is_a()` checks for `IXR_Date` and `IXR_Base64` with `instanceof`, which drops the redundant `is_object()` guard and matches the class checks in `IXR_Server` and `IXR_IntrospectionServer`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add tests for the IXR code paths that check values against an IXR class: `IXR_Server::multiCall()` with scalar and array method results, `IXR_IntrospectionServer::call()` with string, class-name, and integer arguments for a date parameter (and with a real `IXR_Date`), and `IXR_Value::calculateType()` for date, base64, and string values. With deprecations converted to exceptions, these fail on PHP 8.6 if any of the checks goes back to calling `is_a()` with a string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@westonruter

Copy link
Copy Markdown
Member

@dhrupo Please review my additional changes.

@dhrupo

dhrupo commented Nov 2, 2026

Copy link
Copy Markdown
Author

Looks great, thanks for extending it. The IXR_Value::calculateType() one is a nice simplification — instanceof is already false for non-objects, so the is_object() guard was redundant, and it kills the PHP 8.6 is_a()-with-string notice at the same time. Ran it locally: the new non-object tests pass (7/7) and the full xmlrpc/basic.php is green (28 tests, 71 assertions).

Matches the IXR change: PHP 8.6 deprecates `is_a()` with a string when `$allow_string` is false. Text_Diff edits are always `Text_Diff_Op` objects, so the result does not change; this keeps the bundled library consistent with the rest of core. Adds tests for the edit counts and checks that use these class checks.

See #66418.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the changes are accompanied by regression coverage for the updated XML-RPC and Text Diff type checks.

No open issues 🎉

What changed in this PR

This pull request replaces deprecated is_a() checks with instanceof in the XML-RPC IXR and Text Diff implementations, avoiding PHP 8.6 deprecation notices while preserving type-checking behavior.

Changes:

  • Updated IXR server, introspection, and value checks to use instanceof.
  • Updated Text Diff operation and renderer checks.
  • Added XML-RPC and Text Diff regression coverage.
File Description
tests/​phpunit/​tests/​xmlrpc/​basic.php Adds regression coverage for XML-RPC type checks, scalar results, date arguments, and IXR values.
tests/​phpunit/​tests/​diff/​textDiff.php Adds coverage for Text Diff operation counts and copied context rendering.
src/​wp-includes/​Text/​Diff/​Renderer.php Uses instanceof when processing copied diff blocks.
src/​wp-includes/​Text/​Diff.php Uses instanceof for diff operation classification.
src/​wp-includes/​IXR/​class-IXR-value.php Uses instanceof for IXR date and base64 value detection.
src/​wp-includes/​IXR/​class-IXR-server.php Uses instanceof IXR_Error for regular and multicall responses.
src/​wp-includes/​IXR/​class-IXR-introspectionserver.php Uses instanceof IXR_Date for date argument validation.

Review effort: Lite

@peterwilsoncc peterwilsoncc 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.

The source changes look good to me. I've added some notes in the test suite.

Comment thread tests/phpunit/tests/diff/textDiff.php Resolved
Comment thread tests/phpunit/tests/diff/textDiff.php Outdated
/**
* Data provider.
*
* @return array[]

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.

Use a phpstan return type... @westonruter pinging you for advice here.

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.

Improved in 62cfd01

}

/**
* @ticket 66418

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.

Add a one line summary at the top of each test.

For this one it might be:

/**
 * Ensure edit counts are correct.

🔢 Applies to other tests too.

Comment thread tests/phpunit/tests/xmlrpc/basic.php Outdated
Comment on lines +385 to +386
$this->assertIXRError( $result );
$this->assertSame( -32602, $result->code );

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.

Tests with multiple assertions should have a unique $message parameter for each assertion. This is to aid debugging at a later date.

🔢 Applies to other new tests with multiple assertions.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65303
GitHub commit: 54312c7

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 6, 2026
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.

4 participants