Skip to content

Commit 675fe39

Browse files
Code Modernization: Use correct property in IXR_Message::tag_open().
The `IXR_Message` class declares a property `_currentTag`, which is never assigned or used. It does assign to `currentTag` instead, which outside of that one assignment is never used either. Since there are various other underscore-prefixed properties declared on the class, including one named `_currentTagContents` which is used in several places, it appears that the declared property is correct and the assignment is a typo. This commit resolves a notice on PHP 8.2: {{{ Deprecated: Creation of dynamic property IXR_Message::$currentTag is deprecated }}} Follow-up to [1346]. Props bjorsch, kraftbj, jrf, mukesh27, SergeyBiryukov. See #56790. git-svn-id: https://develop.svn.wordpress.org/trunk@55105 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d6afa28 commit 675fe39

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/wp-includes/IXR/class-IXR-message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function parse()
144144
function tag_open($parser, $tag, $attr)
145145
{
146146
$this->_currentTagContents = '';
147-
$this->currentTag = $tag;
147+
$this->_currentTag = $tag;
148148
switch($tag) {
149149
case 'methodCall':
150150
case 'methodResponse':
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Unit tests covering IXR_Message functionality.
4+
*
5+
* @package WordPress
6+
* @subpackage IXR
7+
*/
8+
9+
/**
10+
* Test wp-includes/IXR/class-IXR-message.php
11+
*
12+
* @group xmlrpc
13+
*/
14+
class Tests_XMLRPC_Message extends WP_UnitTestCase {
15+
16+
/**
17+
* Tests that `IXR_Message::tag_open()` does not create a dynamic `currentTag` property,
18+
* and uses the declared `_currentTag` property instead.
19+
*
20+
* The notice that we should not see:
21+
* `Deprecated: Creation of dynamic property IXR_Message::$currentTag is deprecated`.
22+
*
23+
* @ticket 56033
24+
*
25+
* @covers IXR_Message::tag_open
26+
*/
27+
public function test_tag_open_does_not_create_dynamic_property() {
28+
$message = new IXR_Message( '<methodResponse><params><param><value>1</value></param></params></methodResponse>' );
29+
$this->assertTrue( $message->parse() );
30+
$this->assertSame( 'methodResponse', $message->messageType ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
31+
$this->assertSame( array( '1' ), $message->params );
32+
}
33+
34+
}

0 commit comments

Comments
 (0)