Skip to content

Commit

Permalink
cast function call parameters to strings or arrays
Browse files Browse the repository at this point in the history
The SAPNWRFC module by Piers Harding on PHP 5.5 would throw an exception
in case parameters were anything other than strings. All other modules
(saprfc by Koucky on PHP 5.5 and sapnwrfc by Kralik on PHP 7.x) don't
behave that way.
  • Loading branch information
gregor-j committed Mar 2, 2020
1 parent 9acc6da commit 83ea365
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Traits/ParamTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function getInputParams($inputs, $params)
foreach ($inputs as $input) {
$key = $input->getName();
if (array_key_exists($key, $params)) {
$result[$key] = $params[$key];
$result[$key] = $this->typeCastParam($params[$key]);
} elseif (!$input->isOptional()) {
throw new FunctionCallException(sprintf(
'Missing parameter \'%s\' for function call \'%s\'!',
Expand All @@ -40,6 +40,25 @@ private function getInputParams($inputs, $params)
return $result;
}

/**
* Typecast a remote function call parameter.
*
* The SAPNWRFC module by Piers Harding on PHP 5.5 would throw an exception
* in case parameters were anything other than strings. All other modules
* (saprfc by Koucky on PHP 5.5 and sapnwrfc by Kralik on PHP 7.x) don't
* behave that way.
*
* @param mixed $param The parameter to typecast.
* @return string|array
*/
private function typeCastParam($param)
{
if (is_array($param) || is_string($param)) {
return $param;
}
return (string)$param;
}

/**
* Generate a function call parameter array from a list of known tables and the
* previously set parameters.
Expand Down

0 comments on commit 83ea365

Please sign in to comment.