From eecd88d1f111a0c8b556af2f4470fd6ad625b7ea Mon Sep 17 00:00:00 2001 From: Dhrupo Nil Date: Fri, 30 Oct 2026 14:29:20 +0600 Subject: [PATCH 1/6] XML-RPC: Use instanceof instead of is_a() in IXR. 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. --- src/wp-includes/IXR/class-IXR-introspectionserver.php | 2 +- src/wp-includes/IXR/class-IXR-server.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/IXR/class-IXR-introspectionserver.php b/src/wp-includes/IXR/class-IXR-introspectionserver.php index afb05b0e0d2b4..0be5d319d1c12 100644 --- a/src/wp-includes/IXR/class-IXR-introspectionserver.php +++ b/src/wp-includes/IXR/class-IXR-introspectionserver.php @@ -114,7 +114,7 @@ function call($methodname, $args) break; case 'date': case 'dateTime.iso8601': - if (!is_a($arg, 'IXR_Date')) { + if (!($arg instanceof IXR_Date)) { $ok = false; } break; diff --git a/src/wp-includes/IXR/class-IXR-server.php b/src/wp-includes/IXR/class-IXR-server.php index e11f40fbe7c7f..1019718512a8d 100644 --- a/src/wp-includes/IXR/class-IXR-server.php +++ b/src/wp-includes/IXR/class-IXR-server.php @@ -59,7 +59,7 @@ function serve($data = false) $result = $this->call($this->message->methodName, $this->message->params); // Is the result an error? - if (is_a($result, 'IXR_Error')) { + if ($result instanceof IXR_Error) { $this->error($result); } @@ -234,7 +234,7 @@ function multiCall($methodcalls) } else { $result = $this->call($method, $params); } - if (is_a($result, 'IXR_Error')) { + if ($result instanceof IXR_Error) { $return[] = array( 'faultCode' => $result->code, 'faultString' => $result->message From d5a5f06fd6465ea8a08fce282d51b0e163d11bd9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 30 Oct 2026 13:47:20 -0700 Subject: [PATCH 2/6] XML-RPC: Use instanceof in IXR_Value::calculateType(). 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 --- src/wp-includes/IXR/class-IXR-value.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/IXR/class-IXR-value.php b/src/wp-includes/IXR/class-IXR-value.php index 850f318f2c6b2..fcbb64012fb55 100644 --- a/src/wp-includes/IXR/class-IXR-value.php +++ b/src/wp-includes/IXR/class-IXR-value.php @@ -52,10 +52,10 @@ function calculateType() } // Deal with IXR object types base64 and date - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { + if ($this->data instanceof IXR_Date) { return 'date'; } - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { + if ($this->data instanceof IXR_Base64) { return 'base64'; } From f1592d4ad78a65f76f3edbdd89c20ffc0385bbd2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 30 Oct 2026 13:48:19 -0700 Subject: [PATCH 3/6] Tests: Cover IXR class checks on non-object values. 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 --- tests/phpunit/tests/xmlrpc/basic.php | 106 +++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tests/phpunit/tests/xmlrpc/basic.php b/tests/phpunit/tests/xmlrpc/basic.php index c70e2d4bb17fa..6e4d1c7d69fd0 100644 --- a/tests/phpunit/tests/xmlrpc/basic.php +++ b/tests/phpunit/tests/xmlrpc/basic.php @@ -323,6 +323,112 @@ public function test_multicall_with_missing_method_name(): void { $this->assertSame( array( 'Hello!' ), $result[1] ); } + /** + * Tests that a multicall entry returning a non-object result is not treated as an error. + * + * @ticket 66418 + * + * @covers IXR_Server::multiCall + * + * @dataProvider data_multicall_with_non_object_result + * + * @param mixed $value The value the method returns. + */ + public function test_multicall_with_non_object_result( $value ): void { + $this->myxmlrpcserver->callbacks = array( + 'test.echo' => array( $this, 'echo_args' ), + ); + + $result = $this->myxmlrpcserver->multiCall( + array( + array( + 'methodName' => 'test.echo', + 'params' => array( $value ), + ), + ) + ); + + $this->assertSame( array( array( $value ) ), $result ); + } + + /** + * Data provider. + * + * @return array + */ + public static function data_multicall_with_non_object_result(): array { + return array( + 'string' => array( 'IXR_Error' ), + 'integer' => array( 42 ), + 'boolean' => array( true ), + 'non-struct array' => array( array( 'IXR_Error' ) ), + ); + } + + /** + * Tests that the introspection server rejects a non-object argument for a date parameter. + * + * @ticket 66418 + * + * @covers IXR_IntrospectionServer::call + * + * @dataProvider data_introspection_server_rejects_non_date_argument + * + * @param mixed $arg The argument passed for the date parameter. + */ + public function test_introspection_server_rejects_non_date_argument( $arg ): void { + $server = new IXR_IntrospectionServer(); + $server->addCallback( 'test.echo', array( $this, 'echo_args' ), array( 'string', 'dateTime.iso8601' ), 'Echoes a date.' ); + + $result = $server->call( 'test.echo', array( $arg ) ); + + $this->assertIXRError( $result ); + $this->assertSame( -32602, $result->code ); + } + + /** + * Data provider. + * + * @return array + */ + public static function data_introspection_server_rejects_non_date_argument(): array { + return array( + 'date string' => array( '20261030T12:00:00' ), + 'class name' => array( 'IXR_Date' ), + 'integer' => array( 1793361600 ), + ); + } + + /** + * Tests that the introspection server accepts an IXR_Date argument for a date parameter. + * + * @ticket 66418 + * + * @covers IXR_IntrospectionServer::call + */ + public function test_introspection_server_accepts_date_argument(): void { + $server = new IXR_IntrospectionServer(); + $server->addCallback( 'test.echo', array( $this, 'echo_args' ), array( 'string', 'dateTime.iso8601' ), 'Echoes a date.' ); + + $date = new IXR_Date( '20261030T12:00:00' ); + $result = $server->call( 'test.echo', array( $date ) ); + + $this->assertSame( $date, $result ); + } + + /** + * Tests that IXR_Value encodes IXR_Date and IXR_Base64 objects as their XML-RPC types, and strings as strings. + * + * @ticket 66418 + * + * @covers IXR_Value::calculateType + */ + public function test_ixr_value_calculate_type(): void { + $this->assertSame( 'date', ( new IXR_Value( new IXR_Date( '20261030T12:00:00' ) ) )->calculateType() ); + $this->assertSame( 'base64', ( new IXR_Value( new IXR_Base64( 'data' ) ) )->calculateType() ); + $this->assertSame( 'string', ( new IXR_Value( 'IXR_Date' ) )->calculateType() ); + } + /** * @ticket 36586 */ From ae3859d1c8a383088b7c1df7ece62a4f6172e50a Mon Sep 17 00:00:00 2001 From: Dhrupo Date: Wed, 4 Nov 2026 12:08:56 +0600 Subject: [PATCH 4/6] Revisions: Use instanceof instead of is_a() in Text_Diff. 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. --- src/wp-includes/Text/Diff.php | 12 ++--- src/wp-includes/Text/Diff/Renderer.php | 2 +- tests/phpunit/tests/diff/textDiff.php | 75 ++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 tests/phpunit/tests/diff/textDiff.php diff --git a/src/wp-includes/Text/Diff.php b/src/wp-includes/Text/Diff.php index a7a79e50802af..47b90cdb56178 100644 --- a/src/wp-includes/Text/Diff.php +++ b/src/wp-includes/Text/Diff.php @@ -81,8 +81,8 @@ function countAddedLines() { $count = 0; foreach ($this->_edits as $edit) { - if (is_a($edit, 'Text_Diff_Op_add') || - is_a($edit, 'Text_Diff_Op_change')) { + if ($edit instanceof Text_Diff_Op_add || + $edit instanceof Text_Diff_Op_change) { $count += $edit->nfinal(); } } @@ -100,8 +100,8 @@ function countDeletedLines() { $count = 0; foreach ($this->_edits as $edit) { - if (is_a($edit, 'Text_Diff_Op_delete') || - is_a($edit, 'Text_Diff_Op_change')) { + if ($edit instanceof Text_Diff_Op_delete || + $edit instanceof Text_Diff_Op_change) { $count += $edit->norig(); } } @@ -144,7 +144,7 @@ function reverse() function isEmpty() { foreach ($this->_edits as $edit) { - if (!is_a($edit, 'Text_Diff_Op_copy')) { + if (!($edit instanceof Text_Diff_Op_copy)) { return false; } } @@ -162,7 +162,7 @@ function lcs() { $lcs = 0; foreach ($this->_edits as $edit) { - if (is_a($edit, 'Text_Diff_Op_copy')) { + if ($edit instanceof Text_Diff_Op_copy) { $lcs += count($edit->orig); } } diff --git a/src/wp-includes/Text/Diff/Renderer.php b/src/wp-includes/Text/Diff/Renderer.php index 2417670aef062..ccaaa62fbfc95 100644 --- a/src/wp-includes/Text/Diff/Renderer.php +++ b/src/wp-includes/Text/Diff/Renderer.php @@ -90,7 +90,7 @@ function render($diff) /* If these are unchanged (copied) lines, and we want to keep * leading or trailing context lines, extract them from the copy * block. */ - if (is_a($edit, 'Text_Diff_Op_copy')) { + if ($edit instanceof Text_Diff_Op_copy) { /* Do we have any diff blocks yet? */ if (is_array($block)) { /* How many lines to keep as context from the copy diff --git a/tests/phpunit/tests/diff/textDiff.php b/tests/phpunit/tests/diff/textDiff.php new file mode 100644 index 0000000000000..932fa8b415a18 --- /dev/null +++ b/tests/phpunit/tests/diff/textDiff.php @@ -0,0 +1,75 @@ +assertSame( $added, $diff->countAddedLines(), 'Added lines do not match.' ); + $this->assertSame( $deleted, $diff->countDeletedLines(), 'Deleted lines do not match.' ); + $this->assertSame( $is_empty, $diff->isEmpty(), 'isEmpty() does not match.' ); + $this->assertSame( $unchanged_lines, $diff->lcs(), 'Unchanged lines do not match.' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_edit_counts() { + return array( + 'both empty' => array( array(), array(), 0, 0, true, 0 ), + 'identical' => array( array( 'a', 'b' ), array( 'a', 'b' ), 0, 0, true, 2 ), + 'add only' => array( array( 'a' ), array( 'a', 'b' ), 1, 0, false, 1 ), + 'delete only' => array( array( 'a', 'b' ), array( 'a' ), 0, 1, false, 1 ), + 'changed only' => array( array( 'a', 'b', 'c' ), array( 'x', 'b', 'z' ), 2, 2, false, 1 ), + 'change, copy and add' => array( array( 'a', 'b' ), array( 'x', 'b', 'c' ), 2, 1, false, 1 ), + ); + } + + /** + * @ticket 66418 + * + * @covers Text_Diff_Renderer::render + */ + public function test_render_keeps_context_lines_from_copied_blocks() { + $diff = new Text_Diff( 'native', array( array( 'a', 'b', 'c', 'd', 'e' ), array( 'a', 'b', 'X', 'd', 'e' ) ) ); + $renderer = new Text_Diff_Renderer( + array( + 'leading_context_lines' => 1, + 'trailing_context_lines' => 1, + ) + ); + + $this->assertSame( "2,4c2,4\n b\n< c\n---\n> X\n d\n", $renderer->render( $diff ) ); + } +} From 62cfd01c5b82128c0e342938dd3afffd6dbc09b5 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 5 Nov 2026 10:52:12 -0700 Subject: [PATCH 5/6] Narrow types in test --- tests/phpunit/tests/diff/textDiff.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/diff/textDiff.php b/tests/phpunit/tests/diff/textDiff.php index 932fa8b415a18..b5be97609b0c5 100644 --- a/tests/phpunit/tests/diff/textDiff.php +++ b/tests/phpunit/tests/diff/textDiff.php @@ -24,14 +24,14 @@ public static function set_up_before_class() { * * @dataProvider data_edit_counts * - * @param string[] $from_lines Lines before the change. - * @param string[] $to_lines Lines after the change. - * @param int $added Expected number of added lines. - * @param int $deleted Expected number of deleted lines. - * @param bool $is_empty Whether the diff is expected to have no changes. - * @param int $unchanged_lines Expected number of unchanged lines. + * @param non-empty-string[] $from_lines Lines before the change. + * @param non-empty-string[] $to_lines Lines after the change. + * @param non-negative-int $added Expected number of added lines. + * @param non-negative-int $deleted Expected number of deleted lines. + * @param bool $is_empty Whether the diff is expected to have no changes. + * @param non-negative-int $unchanged_lines Expected number of unchanged lines. */ - public function test_edit_counts( $from_lines, $to_lines, $added, $deleted, $is_empty, $unchanged_lines ) { + public function test_edit_counts( array $from_lines, array $to_lines, int $added, int $deleted, bool $is_empty, int $unchanged_lines ) { $diff = new Text_Diff( 'native', array( $from_lines, $to_lines ) ); $this->assertSame( $added, $diff->countAddedLines(), 'Added lines do not match.' ); @@ -41,11 +41,11 @@ public function test_edit_counts( $from_lines, $to_lines, $added, $deleted, $is_ } /** - * Data provider. + * Data provider for {@see self::test_edit_counts()}. * - * @return array[] + * @return array */ - public static function data_edit_counts() { + public static function data_edit_counts(): array { return array( 'both empty' => array( array(), array(), 0, 0, true, 0 ), 'identical' => array( array( 'a', 'b' ), array( 'a', 'b' ), 0, 0, true, 2 ), From 567ed8463e2167e988579b08fcee1cb8d75237db Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 6 Nov 2026 12:35:51 +1100 Subject: [PATCH 6/6] Add messages to new tests. --- tests/phpunit/tests/xmlrpc/basic.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/xmlrpc/basic.php b/tests/phpunit/tests/xmlrpc/basic.php index 6e4d1c7d69fd0..d8745fe6a6a75 100644 --- a/tests/phpunit/tests/xmlrpc/basic.php +++ b/tests/phpunit/tests/xmlrpc/basic.php @@ -382,8 +382,9 @@ public function test_introspection_server_rejects_non_date_argument( $arg ): voi $result = $server->call( 'test.echo', array( $arg ) ); - $this->assertIXRError( $result ); - $this->assertSame( -32602, $result->code ); + $this->assertIXRError( $result, 'A non-date argument should return an IXR_Error.' ); + $this->assertSame( -32602, $result->code, 'The error code should indicate invalid method parameters.' ); + $this->assertSame( 'server error. invalid method parameters', $result->message, 'The error message should indicate an invalid parameter type rather than a wrong parameter count.' ); } /** @@ -424,9 +425,9 @@ public function test_introspection_server_accepts_date_argument(): void { * @covers IXR_Value::calculateType */ public function test_ixr_value_calculate_type(): void { - $this->assertSame( 'date', ( new IXR_Value( new IXR_Date( '20261030T12:00:00' ) ) )->calculateType() ); - $this->assertSame( 'base64', ( new IXR_Value( new IXR_Base64( 'data' ) ) )->calculateType() ); - $this->assertSame( 'string', ( new IXR_Value( 'IXR_Date' ) )->calculateType() ); + $this->assertSame( 'date', ( new IXR_Value( new IXR_Date( '20261030T12:00:00' ) ) )->calculateType(), 'An IXR_Date object should be typed as a date.' ); + $this->assertSame( 'base64', ( new IXR_Value( new IXR_Base64( 'data' ) ) )->calculateType(), 'An IXR_Base64 object should be typed as base64.' ); + $this->assertSame( 'string', ( new IXR_Value( 'IXR_Date' ) )->calculateType(), 'A string matching a class name should be typed as a string.' ); } /**