PHP Conference Japan 2024

ArithmeticError

(PHP 7, PHP 8)

簡介

當執行數學運算時發生錯誤,會拋出 ArithmeticError。這些錯誤包括嘗試以負數進行位元位移,以及任何呼叫 intdiv() 導致值超出 int 可能範圍的情況。

類別概要

class ArithmeticError extends Error {
/* 繼承的屬性 */
保護 字串 $message = "";
私有 字串 $string = "";
保護 整數 $code;
保護 字串 $file = "";
保護 整數 $line;
私有 陣列 $trace = [];
私有 ?Throwable $previous = null;
/* 繼承的方法 */
公開 Error::__construct(字串 $message = "", 整數 $code = 0, ?Throwable $previous = null)
最終 公開 Error::getMessage(): 字串
最終 公開 Error::getCode(): 整數
最終 公開 Error::getFile(): 字串
最終 公開 Error::getLine(): 整數
最終 公開 Error::getTrace(): 陣列
}
新增註解

使用者貢獻的筆記 1 則筆記

nima dot shirinzadeh at gmail dot com
4 年前
第一個範例以正數位移,結果為 4,但第二個範例以負數位移,結果是 ArithmeticError(此範例與左移相同)
<?php

$shif
=1;
$number = 8;
$result = $number >> $shif;
echo
$result; //// 1000 >> 01000 = 4

$shif =-1;
$number = 8;
$result = $number >> $shif;
////結果是 ArithmeticError
?>
To Top