I am calling to a PHP file, from a nodejs app and sending argument, while one of the arguments should be JSON (stringified of course)
It isn't working as expected, as the string appears to be multiple arguments and need to be escaped or correctly.
Trying to split the problem, I created a new php file, trying to execute from the outside (in this example from command line) ->
running the following command
php test.php {"access_token":"acccess_token","id_token":"id_token","refresh_token":"refresh-token","token_type":"token_type","expiry_date":1515578624982,"expires_in":3600}
here is the code sample that is failing
<?php
$json = $argv[1];
$res = json_decode($json,true);
echo "CHECK-ERROR".json_last_error().PHP_EOL."-----".PHP_EOL;
echo "END RESULTS".PHP_EOL.$res.PHP_EOL."-------".PHP_EOL;
?>
here is the output
so few interesting facts:
- Changing the code to have the argument as a local variable - works fine.
- putting the json in single quotes '{...}' - works fine.
- calling the php from the NodeJS using '${jsonStringified}'
- works fine. (as it the same idea as the abovemnetinoed
The question is what other solutions exists? (e.g. encoding, escaping) rather than this small tweak?