3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class RPCInterface{ const STATUS_OK = 200; const STATUS_INVALID_CREDENTIALS = 401; const STATUS_RESSOURCE_NOT_FOUND = 404; const STATUS_INTERNAL_ERROR = 500; const STATUS_NOT_IMPLEMENTED = 501; const STATUS_SERVICE_UNAVAILABLE = 503; const ENCAP_RAW = 0; const ENCAP_AES256 = 1; const ENCAP_RSA2048 = 2; protected $encap = 0; public function getRequestStr($auth, $method, $data){ $req = new stdClass(); $req->auth = $auth; $req->method = $method; $req->data = $data; $reqStr = $this->encode($req); return $reqStr; } public function getResponse($respStr){ $resp = $this->decode($respStr); return $resp; } public function encode($obj){ $str = serialize($obj);// json_encode($str); $str = $this->encapsulate($str); return $str; } public function decode($str){ $str = $this->decapsulate($str); $obj = unserialize($str); return $obj; } public function encapsulate($str){ switch($this->encap){ case self::ENCAP_RAW: $str = base64_encode($str); break; case self::ENCAP_AES256: die('TODO IMPL AES245'); // TODO FIXME break; case self::ENCAP_RSA2048: die('TODO IMPL RSA2048'); // TODO FIXME break; default: die('UNKNOWN_ENCAP_ALG'); } return $str; } public function decapsulate($str){ switch($this->encap){ case self::ENCAP_RAW: $str = base64_decode($str); break; case self::ENCAP_AES256: die('TODO IMPL AES245'); // TODO FIXME break; case self::ENCAP_RSA2048: die('TODO IMPL RSA2048'); // TODO FIXME break; default: die('UNKNOWN_ENCAP_ALG'); } return $str; } public function responseOk($resp){ return ($resp->status == self::STATUS_OK); } public function getError($resp){ return $resp->data['error_num'].' '.$resp->data['error_msg']; } public function getErrorDesc($resp){ return $resp->data['error_desc']; } public function sendRequest($url, $auth, $method, $data){ $reqStr = $this->getRequestStr($auth, $method, $data); $request = xmlrpc_encode_request($method, $reqStr); // maybe do not use xmlrpc_ at all... $context = stream_context_create(array('http' => array( 'method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request ))); print_r($context); //$file = file_get_contents($url, false, $context); $resp = $this->getResponse($file); if($this->responseOk($resp)){ $resp->error = false; }else{ $resp->error = true; } return $resp; } } $rpc = new RPCInterface(); $auth = array(); $auth['customer_id'] = '4843929'; $auth['customer_pw'] = 'pw0rdRem0tE0815'; $auth['domain_id'] = '429'; $auth['domain_sec'] = 'a98bf32409cd1fd298e'; $method = 'status.ping'; $url = 'www.example.com'; $data = array(); $req = $rpc->getRequestStr($auth, $method, $data); $dec = $rpc->getResponse($req); echo $req; echo "\r\n"; echo print_r($dec, true); $resp = $rpc->sendRequest($url, $auth, $method, $data); if($resp->error){ echo "Error occured!\r\n"; } ?>
Output for 7.0.0 - 7.1.0
Tzo4OiJzdGRDbGFzcyI6Mzp7czo0OiJhdXRoIjthOjQ6e3M6MTE6ImN1c3RvbWVyX2lkIjtzOjc6IjQ4NDM5MjkiO3M6MTE6ImN1c3RvbWVyX3B3IjtzOjE1OiJwdzByZFJlbTB0RTA4MTUiO3M6OToiZG9tYWluX2lkIjtzOjM6IjQyOSI7czoxMDoiZG9tYWluX3NlYyI7czoxOToiYTk4YmYzMjQwOWNkMWZkMjk4ZSI7fXM6NjoibWV0aG9kIjtzOjExOiJzdGF0dXMucGluZyI7czo0OiJkYXRhIjthOjA6e319 stdClass Object ( [auth] => Array ( [customer_id] => 4843929 [customer_pw] => pw0rdRem0tE0815 [domain_id] => 429 [domain_sec] => a98bf32409cd1fd298e ) [method] => status.ping [data] => Array ( ) ) Fatal error: Uncaught Error: Call to undefined function xmlrpc_encode_request() in /in/JZ2ug:93 Stack trace: #0 /in/JZ2ug(134): RPCInterface->sendRequest('www.example.com', Array, 'status.ping', Array) #1 {main} thrown in /in/JZ2ug on line 93
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Tzo4OiJzdGRDbGFzcyI6Mzp7czo0OiJhdXRoIjthOjQ6e3M6MTE6ImN1c3RvbWVyX2lkIjtzOjc6IjQ4NDM5MjkiO3M6MTE6ImN1c3RvbWVyX3B3IjtzOjE1OiJwdzByZFJlbTB0RTA4MTUiO3M6OToiZG9tYWluX2lkIjtzOjM6IjQyOSI7czoxMDoiZG9tYWluX3NlYyI7czoxOToiYTk4YmYzMjQwOWNkMWZkMjk4ZSI7fXM6NjoibWV0aG9kIjtzOjExOiJzdGF0dXMucGluZyI7czo0OiJkYXRhIjthOjA6e319 stdClass Object ( [auth] => Array ( [customer_id] => 4843929 [customer_pw] => pw0rdRem0tE0815 [domain_id] => 429 [domain_sec] => a98bf32409cd1fd298e ) [method] => status.ping [data] => Array ( ) ) Fatal error: Call to undefined function xmlrpc_encode_request() in /in/JZ2ug on line 93
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/JZ2ug on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/JZ2ug on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/JZ2ug on line 6
Process exited with code 255.