3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); function & XMLRPC_adjustValue(&$current_node){ if(is_array($current_node)){ if(isset($current_node['array'])){ if(!is_array($current_node['array']['data'])){ #If there are no elements, return an empty array return array(); }else{ #echo "Getting rid of array -> data -> value<br>\n"; $temp = &$current_node['array']['data']['value']; if(is_array($temp) and array_key_exists(0, $temp)){ $count = count($temp); for($n=0;$n<$count;$n++){ $temp2[$n] = &XMLRPC_adjustValue($temp[$n]); } $temp = &$temp2; }else{ $temp2 = &XMLRPC_adjustValue($temp); $temp = array(&$temp2); #I do the temp assignment because it avoids copying, # since I can put a reference in the array #PHP's reference model is a bit silly, and I can't just say: # $temp = array(&XMLRPC_adjustValue(&$temp)); } } }elseif(isset($current_node['struct'])){ if(!is_array($current_node['struct'])){ #If there are no members, return an empty array return array(); }else{ #echo "Getting rid of struct -> member<br>\n"; $temp = &$current_node['struct']['member']; if(is_array($temp) and array_key_exists(0, $temp)){ $count = count($temp); for($n=0;$n<$count;$n++){ #echo "Passing name {$temp[$n][name]}. Value is: " . show($temp[$n][value], var_dump, true) . "<br>\n"; $temp2[$temp[$n]['name']] = &XMLRPC_adjustValue($temp[$n]['value']); #echo "adjustValue(): After assigning, the value is " . show($temp2[$temp[$n]['name']], var_dump, true) . "<br>\n"; } }else{ #echo "Passing name $temp[name]<br>\n"; $temp2[$temp['name']] = &XMLRPC_adjustValue($temp['value']); } $temp = &$temp2; } }else{ $types = array('string', 'int', 'i4', 'double', 'dateTime.iso8601', 'base64', 'boolean'); $fell_through = true; foreach($types as $type){ if(array_key_exists($type, $current_node)){ #echo "Getting rid of '$type'<br>\n"; $temp = &$current_node[$type]; #echo "adjustValue(): The current node is set with a type of $type<br>\n"; $fell_through = false; break; } } if($fell_through){ $type = 'string'; #echo "Fell through! Type is $type<br>\n"; } switch ($type){ case 'int': case 'i4': $temp = (int)$temp; break; case 'string': $temp = (string)$temp; break; case 'double': $temp = (double)$temp; break; case 'boolean': $temp = (bool)$temp; break; } } }else{ $temp = (string)$current_node; } return $temp; } function XMLRPC_getParams($request){ if(!is_array($request['methodCall']['params'])){ #If there are no parameters, return an empty array return array(); }else{ #echo "Getting rid of methodCall -> params -> param<br>\n"; $temp = &$request['methodCall']['params']['param']; if(is_array($temp) and array_key_exists(0, $temp)){ $count = count($temp); for($n = 0; $n < $count; $n++){ #echo "Serializing parameter $n<br>"; $temp2[$n] = &XMLRPC_adjustValue($temp[$n]['value']); } }else{ $temp2[0] = &XMLRPC_adjustValue($temp['value']); } $temp = &$temp2; return $temp; } } function XMLRPC_getMethodName($methodCall){ #returns the method name return $methodCall['methodCall']['methodName']; } function XMLRPC_request($site, $location, $methodName, $params = NULL, $user_agent = NULL){ $site = explode(':', $site); if(isset($site[1]) and is_numeric($site[1])){ $port = $site[1]; }else{ $port = 80; } $site = $site[0]; $data["methodCall"]["methodName"] = $methodName; $param_count = count($params); if(!$param_count){ $data["methodCall"]["params"] = NULL; }else{ for($n = 0; $n<$param_count; $n++){ $data["methodCall"]["params"]["param"][$n]["value"] = $params[$n]; } } $data = XML_serialize($data); if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "<p>Received the following parameter list to send:</p>" . XMLRPC_show($params, 'print_r', true)); } $conn = fsockopen ($site, $port); #open the connection if(!$conn){ #if the connection was not opened successfully if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "<p>Connection failed: Couldn't make the connection to $site.</p>"); } return array(false, array('faultCode'=>10532, 'faultString'=>"Connection failed: Couldn't make the connection to $site.")); }else{ $headers = "POST $location HTTP/1.0\r\n" . "Host: $site\r\n" . "Connection: close\r\n" . ($user_agent ? "User-Agent: $user_agent\r\n" : '') . "Content-Type: text/xml\r\n" . "Content-Length: " . strlen($data) . "\r\n\r\n"; fputs($conn, "$headers"); fputs($conn, $data); if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "<p>Sent the following request:</p>\n\n" . XMLRPC_show($headers . $data, 'print_r', true)); } #socket_set_blocking ($conn, false); $response = ""; while(!feof($conn)){ $response .= fgets($conn, 1024); } fclose($conn); #strip headers off of response $data = XML_unserialize(substr($response, strpos($response, "\r\n\r\n")+4)); if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "<p>Received the following response:</p>\n\n" . XMLRPC_show($response, 'print_r', true) . "<p>Which was serialized into the following data:</p>\n\n" . XMLRPC_show($data, 'print_r', true)); } if(isset($data['methodResponse']['fault'])){ $return = array(false, XMLRPC_adjustValue($data['methodResponse']['fault']['value'])); if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "<p>Returning:</p>\n\n" . XMLRPC_show($return, 'var_dump', true)); } return $return; }else{ $return = array(true, XMLRPC_adjustValue($data['methodResponse']['params']['param']['value'])); if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){ XMLRPC_debug('XMLRPC_request', "<p>Returning:</p>\n\n" . XMLRPC_show($return, 'var_dump', true)); } return $return; } } }
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
46.71 ms | 401 KiB | 8 Q