略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ArithmeticError

2024-12-20

ArithmeticError

(PHP 7, PHP 8)

简介

当执行数学运算发生错误时抛出 ArithmeticError 。 这些错误包括尝试执行负数的位移,以及对任何可能会导致值超出 int 的范围 intdiv() 调用。

类摘要

class ArithmeticError extends Error {
/* 继承的属性 */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* 继承的方法 */
final public Error::getMessage(): string
final public Error::getPrevious(): ?Throwable
final public Error::getCode(): int
final public Error::getFile(): string
final public Error::getLine(): int
final public Error::getTrace(): array
final public Error::getTraceAsString(): string
public Error::__toString(): string
private Error::__clone(): void
}
add a noteadd a note

User Contributed Notes 1 note

up
1
nima dot shirinzadeh at gmail dot com
1 year ago
the first example shifted by the positive number and the result is 4, but the second example shifted by the negative number and the result is ArithmeticError(this example is the same for left shift)
<?php

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

$shif =-1;
$number = 8;
$result $number >> $shif;
////result is ArithmeticError
?>

官方地址:https://www.php.net/manual/en/class.arithmeticerror.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3