亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP 7 ?? ??

PHP 7??? ???? ??? ???? ??? ???????. PHP 5? ?? ?? ?? ????? ?? ???? ??? ?? Error ??? ?????.

?? ??? ?? ??? ?? ???? try/catch ???? catch? ? ????. ???? try / catch ??? ??? ??? ?? ?? ?? ??(set_Exception_handler()? ?? ???)? ?????. ?? ???? ???? ?? ?? ?? ???? ?????. ?, ???? ??? ?????.

Error ???? Exception ????? ???? ???? catch (Exception $e) { ... }? ?? ??? Error? ??? ? ????. catch (Error $e) { ... }? ?? ??? ????? ?? ???(set_Exception_handler())? ???? ??? ?? ? ????.

?? ?? ?? ??

  • Error
    • ArithmeticError
    • AssertionError
    • DivisionByZero ??
    • ParseError
    • TypeError
  • Exception
    • ...

1458887252-2773-exception-hiearchy.jpg

Instance

<?php 
class MathOperations  
{ 
   protected $n = 10; 

   // 求余數(shù)運(yùn)算,除數(shù)為 0,拋出異常 
   public function doOperation(): string 
   { 
      try { 
         $value = $this->n % 0; 
         return $value; 
      } catch (DivisionByZeroError $e) { 
         return $e->getMessage(); 
      } 
   } 
} 

$mathOperationsObj = new MathOperations(); 
print($mathOperationsObj->doOperation()); 
?>

? ???? ??? ?? ??? ??? ????.

Modulo by zero
???? ??
||
<?php class MathOperations { protected $n = 10; // 求余數(shù)運(yùn)算,除數(shù)為 0,拋出異常 public function doOperation(): string { try { $value = $this->n % 0; return $value; } catch (DivisionByZeroError $e) { return $e->getMessage(); } } } $mathOperationsObj = new MathOperations(); print($mathOperationsObj->doOperation()); ?>