Make WordPress Core

Opened 15 years ago

Closed 14 years ago

#10778 closed defect (bug) (fixed)

PHP Warning in class-IXR.php when $method is array

Reported by: orensol's profile orensol Owned by: josephscott's profile josephscott
Milestone: 3.0 Priority: normal
Severity: normal Version:
Component: XML-RPC Keywords: xmlrpc, class-IXR, warning
Focuses: Cc:


On line 352 in class-IXR.php, there's a call to substr() with $method as the first parameter, which issues the following PHP warning if $method is an array:

PHP Warning: substr() expects parameter 1 to be string, array given

Only later on line 363 there's a call to is_array() on $method.

Suggested fix:
condition the call to substr if !is_array($method).

Attachments (1)

my_xmlrpc_server.php (370 bytes) - added by orensol 15 years ago.
Example Extended XMLRPC Server

Download all attachments as: .zip

Change History (7)

#1 @josephscott
15 years ago

  • Cc joseph@… added
  • Component changed from General to XML-RPC
  • Milestone changed from Unassigned to 2.9
  • Owner set to josephscott

Can you outline the exact steps to reproduce the warning so that I can confirm it and work up a patch?

15 years ago

Example Extended XMLRPC Server

#2 @orensol
15 years ago

Include the attached my_xmlrpc_server.php at some point (I do it inside a mu-plugin).

Then call the XMLRPC My.someFunction.

This should generate the PHP Warning.

#3 @josephscott
15 years ago

Can you provide steps to reproduce the warning using the core WP code?

As a side note, you can add and alter the XML-RPC methods WP provides by just using the built filter system.

#4 @G.hue
15 years ago

There is a problem at line 352 of wp-includes/class-IXR.php when system call:

substr($method, 0, 5)

$method can be an array, as you can see line 363 of wp-includes/class-IXR.php


If $method is an array, the substr function on line 352 display a Warning Error.

If $method is an array, system will display a Warning Error but continue doing well on server side.

If $method is an array, the client will NOT be ok when it analyse the returned xml because there is the Warning displaying on the XML returned, not well formed.

On xmlrpc.php there is that on line 57/58:

// Turn off all warnings and errors.
// error_reporting(0);

If you uncomment error_reporting(0), you can't see the bug. Maybe a relation?

$method is an array when you call a method from an object plugin, like that :

In constructor class:

add_action('xmlrpc_methods', array(&$this, 'xmlrpc_methods'));

Then in the class of plugin, the given method array array(&$this, 'xmlrpc_testConnexion') is the problem:

public function xmlrpc_methods($methods) {
		$methods['pu.testConnexion'] = array(&$this, 'xmlrpc_testConnexion');;
		return $methods;

And the function in the class:

public function xmlrpc_testConnexion($args){
		return "test";

The xml returned is :

<br /><b>Warning</b>:  substr() expects parameter 1 to be string, array given in <b>C:\XXX\class-IXR.php</b> on line <b>352</b><br /><methodResponse><params><param><value><string>test</string></value></param></params></methodResponse>"

PHP Version is 5.3.0

#5 @markjaquith
15 years ago

  • Milestone changed from 2.9 to 3.0

#6 @nacin
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [13958]) Check for string, as method may be an array. fixes #10778

Note: See TracTickets for help on using tickets.