Is there a way to convert any value especially boolean and arrays into strings? I want to do this for a cleaner error message in a function. Right now all I can get in this example below it this for an error message
Fatal error: Uncaught InvalidArgumentException: $argument cannot be in /file.php:## Stack trace: #0 /file.php:(##): myFunction(false) #1 {main} thrown in /file.php on line 47
I want it to say "$argument cannot be false" not "$argument cannot be "
<?php
myFunction(false);
myFunction(array('a', 'b'));
//Version 0.5
function myFunction($argument) {
if (!is_string($argument)) {
throw new InvalidArgumentException('$argument cannot be ' . strval($argument));
}
//...
}
?>
function (string $argument)strval($string)but nowhere declared$string?(string)true === '1'and(string)false === ''. Welcome to PHP.json_encode($argument)orgettype($argument)for a textual depiction or description of the value or type.$argeumentvs$arguement? Also swap'...'pair to a"...."pair?