Ошибка ArithmeticError

(PHP 7, PHP 8)

Π’Π²Π΅Π΄Π΅Π½ΠΈΠ΅

Ошибка ArithmeticError Π²ΠΎΠ·Π½ΠΈΠΊΠ°Π΅Ρ‚ ΠΏΡ€ΠΈ Π½Π΅ΠΊΠΎΡ€Ρ€Π΅ΠΊΡ‚Π½Ρ‹Ρ… матСматичСских опСрациях ΠΈΠ»ΠΈ нСдопустимом Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅. К Ρ‚Π°ΠΊΠΈΠΌ ошибкам относятся ΠΏΠΎΠΏΡ‹Ρ‚ΠΊΠΈ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ сдвиг Π±ΠΈΡ‚ΠΎΠ² Π½Π° ΠΎΡ‚Ρ€ΠΈΡ†Π°Ρ‚Π΅Π»ΡŒΠ½ΡƒΡŽ Π²Π΅Π»ΠΈΡ‡ΠΈΠ½Ρƒ ΠΈΠ»ΠΈ Π²Ρ‹Π·ΠΎΠ² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ intdiv(), ΠΏΡ€ΠΈ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌ частноС Π²Ρ‹Ρ…ΠΎΠ΄ΠΈΡ‚ Π·Π° ΠΏΡ€Π΅Π΄Π΅Π»Ρ‹ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹Ρ… Π³Ρ€Π°Π½ΠΈΡ† Ρ‚ΠΈΠΏΠ° int.

ΠžΠ±Π·ΠΎΡ€ класса

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;
/* НаслСдуСмыС ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ */
public function Error::__construct(string $message = "", int $code = 0, ?Throwable $previous = null)
final public function Error::getMessage(): string
final public function Error::getPrevious(): ?Throwable
final public function Error::getCode(): int
final public function Error::getFile(): string
final public function Error::getLine(): int
final public function Error::getTrace(): array
final public function Error::getTraceAsString(): string
public function Error::__toString(): string
private function Error::__clone(): void
}
οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 1 note

up
-1
nima dot shirinzadeh at gmail dot com ΒΆ
5 years 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
?>