How do I execute the transaction(123) function?
The response via API is: transaction(123)
I store this in the $response varible.
<?php
function transaction($orderid) {
return $orderid;
}
//api response
$response = "transaction(123)";
try {
$orderid = call_user_func($response);
echo $orderid;
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
According to the manual page
call_user_func()should be called with two parameters in your use case.This means you must extract the function and parameter separately from your
$responsevariable:Would result in the
$matchesarray containing the function name at index 1 and the parameter at index 2.So you would then do:
Obviously you need to be very careful with the values if they are coming from an untrusted source.