CakeFest 2017 NYC, the Official CakePHP Conference

Voting

Please answer this simple SPAM challenge: zero minus zero?
(Example: nine)

The Note You're Voting On

ohcc at 163 dot com
1 year ago
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){ // failed to catch it
       
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();
    }
?>

<< Back to user notes page

To Top