Type declarations will trigger Uncaught TypeError when a different type is passed. And it cannot be caught with the Exception class.
<?php
function xc(array $a){
}
try{
xc(4);
}catch (Exception $e){ echo $e->getMessage();
}
?>
You should use TypeError instead for PHP 7+,
<?php
function xc(array $a){
}
try{
xc(4);
}catch (TypeError $e){
echo $e->getMessage();
}
?>
In php version prior to 7.0, you should translate Catchable fatal errors to an exception and then catch it.
<?php
function exceptionErrorHandler($errNumber, $errStr, $errFile, $errLine ) {
throw new ErrorException($errStr, 0, $errNumber, $errFile, $errLine);
}
set_error_handler('exceptionErrorHandler');
function s(array $a){
}
try{
s(4);
}catch (Exception $e){
echo $e->getMessage();
}
?>