In JavaScript this is how I create throw errors if the parameter of a function is a invalid type.
function myFunction(num)
if (typeof(num) !== 'number') {
throw TypeError('num cannot be' + num);
}
}
How do I do this on PHP? I know there is a throw command but how do you set the error type. In the JavaScript example above I set it to be a TypeError, how do you set the error type for a PHP throw error and what are the error types in PHP?
function myFunction($num)
if (gettype($num) !== 'boolean') {
throw new Exception('$num cannot be ' , $num);;
}
}