3v4l.org

run code in 300+ PHP versions simultaneously
<?php // token used for webservice authentication define('AUTH_TOKEN', 'UvNdcV8tYZUQCDc2W8re7CvHckWzQcT5'); // define the webservice endpoint path define('WS_ENDPOINT', 'https://tina.talmatravel.co.il/html/demoTina3/tina/disp.php?module=RemoteData/EntityManagementWs&action=handleRequest'); /** * Execute JSON webservice request * @param array $operationParams * @param stdClass $request * @throws Exception * @return mixed */ function restJsonCall(array $operationParams, stdClass $request = null) { $endPoint = str_replace(" ", "%20", WS_ENDPOINT).'&'.http_build_query($operationParams); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $endPoint); curl_setopt($ch, CURLOPT_POST, 1); if ($request) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request)); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec ($ch); if (curl_error($ch)) { throw new Exception('CURL eror: '.curl_errno($ch)); } $responseDecoded = json_decode($response); // invalid response if (!$responseDecoded) { throw new Exception('Invalid REST response: '.$response); } elseif ($responseDecoded->status!='ok') { throw new Exception('Error while executing operation: '. $responseDecoded->message); } return $responseDecoded; } // STEP 1: AUTHENTICATION // get the auth token first $operationParams_Authenticate = array('operation' => 'authenticate', 'authToken' => AUTH_TOKEN); $rq = new stdClass(); $rs = restJsonCall($operationParams_Authenticate, $rq); $token = $rs->sessionToken; // STEP 2: INSERT NEW SUPPLIER // initialize hit count; must be incremented on each request $hitCount = 0; // Prepare the request body $supplierInsertRequest = new stdClass(); $supplierInsertRequest->alias = 'COMPANY ALIAS'; $supplierInsertRequest->company = 'COMPANY NAME'; $supplierInsertRequest->email = 'companyname@noreply.com'; // assemble the operationParams array $operationParamsForSupplierInsert = array( 'sessionToken' => $token, 'hitCount' => ++$hitCount, 'entity' => 'supplier', 'operation' => 'insert', ); // call the operation $supplierInsertResponse = restJsonCall($operationParamsForSupplierInsert, $supplierInsertRequest); // display the response var_dump(json_encode($supplierInsertResponse, JSON_PRETTY_PRINT)); //get supplier id $idSupplier = $supplierInsertResponse->idEntity; // STEP 3: SELECT INSERTED SUPPLIER // for UPDATE / DELETE / SELECT, a valid ID must be specified // assemble the operationParams array: $operationParamsForSupplierSelect = array( 'sessionToken' => $token, 'hitCount' => ++$hitCount, 'entity' => 'supplier', 'operation' => 'select', 'id' => $idSupplier, ); // call the operation $supplierSelectResponse = restJsonCall($operationParamsForSupplierSelect); // display the response var_dump(json_encode($supplierSelectResponse, JSON_PRETTY_PRINT)); // STEP 4: DELETE INSERTED SUPPLIER // for UPDATE / DELETE / SELECT, a valid ID must be specified // assemble the operationParams array: $operationParamsForSupplierDelete = array( 'sessionToken' => $token, 'hitCount' => ++$hitCount, 'entity' => 'supplier', 'operation' => 'delete', 'id' => $idSupplier, ); // call the operation $supplierDeleteResponse = restJsonCall($operationParamsForSupplierDelete); // display the response var_dump(json_encode($supplierDeleteResponse, JSON_PRETTY_PRINT));
Output for 7.1.0 - 7.1.22, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/NsVk2:21 Stack trace: #0 /in/NsVk2(53): restJsonCall(Array, Object(stdClass)) #1 {main} thrown in /in/NsVk2 on line 21
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/NsVk2:21 Stack trace: #0 /in/NsVk2(53): restJsonCall(Array, Object(stdClass)) #1 {main} thrown in /in/NsVk2 on line 21
Process exited with code 255.
Output for 5.6.38
Fatal error: Call to undefined function curl_init() in /in/NsVk2 on line 21
Process exited with code 255.

preferences:
158.44 ms | 401 KiB | 172 Q