๐Ÿ“š
Laravel Tips
  • Introduction
  • ๋ผ๋ผ๋ฒจ ์ƒํƒœ๊ณ„
    • ๋ผ๋ผ๋ฒจ ๋ฐœ๋ ›(Laravel Valet)์—์„œ Node ์‹คํ–‰ํ•˜๊ธฐ
    • ๋ผ๋ผ๋ฒจ ๋…ธ๋ฐ” ํ›‘์–ด๋ณด๊ธฐ
    • ๋ผ๋ผ๋ฒจ ๋…ธ๋ฐ”์˜ Envoyer ๋ฐฐํฌ์˜ ์‹ค์ „
    • Envoyer์—์„œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ๊ฐœ๋ฐœ ํŒ
    • ํผ๋ฏธ์…˜ ์—๋Ÿฌ์—†์ด PHP๋ฅผ ๊ตฌ๋™ํ•˜๊ธฐ ์œ„ํ•œ ์„œ๋ฒ„ ์„ธํŒ…๋ฒ•
    • ๋ผ๋ผ๋ฒจ์ด ์• ์šฉํ•˜๋Š” ::class ํ†บ์•„๋ณด๊ธฐ
    • ๋ผ๋ผ๋ฒจ์—์„œ์˜ ๋ฒ„์ „์˜ ์˜๋ฏธ
    • ๋ผ๋ผ๋ฒจ ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ .aliases ํŒŒ์ผ
    • ๋ผ๋ผ๋ฒจ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ• ๋น„๊ต
    • PHP ์Šคํฌ๋ฆฝํŠธ๋ฅผ php ๋ช…๋ น์–ด ์—†์ด ์‚ฌ์šฉํ•˜๋Š” ๋ฒ•
    • ๊ตญ์ œํ™”์˜ ํ•„์ˆ˜ ์ต์Šคํ…์…˜, NumberFormatter
    • ๋ผ๋ผ๋ฒจ์—์„œ ๋ทฐํ—ฌํผ๋ฅผ ๋งŒ๋“ค์–ด ๋ด…์‹œ๋‹ค
  • Knowledge Acquisition
    • Error ํ˜น์€ Warning
    • NumberFormatter class example
    • Exception + Error = Throwable Tree in PHP 7 over
    • Coding Style Preset
    • Programming Case Types
Powered by GitBook
On this page
  • Introduction
  • Example & Output
  • ArithmeticError
  • DivisionByZeroError
  • AssertionError
  • ArgumentCountError
  • TypeError
  • Runtime Exceptions

Was this helpful?

Edit on GitHub
  1. Knowledge Acquisition

Exception + Error = Throwable Tree in PHP 7 over

PreviousNumberFormatter class exampleNextCoding Style Preset

Last updated 1 year ago

Was this helpful?

Introduction

PHP 7.x introduces new Throwable interface together Error and Exception.

Interface Throwable
+-- Error
|   +-- ArithmeticError
|   |   +-- DivisionByZeroError
|   +-- AssertionError
|   +-- CompileError (PHP 7.3 over)
|       +-- ParseError
|   +-- TypeError
|       +-- ArgumentCountError
+-- Exception
    +-- ClosedGeneratorException
    +-- DOMException
    +-- ErrorException
    +-- IntlException
    +-- LogicException
    |   +-- BadFunctionCallException
    |   |   +-- BadMethodCallException
    |   +-- DomainException
    |   +-- InvalidArgumentException
    |   +-- LengthException
    |   +-- OutOfRangeException
    +-- PharException
    +-- ReflectionException
    +-- RuntimeException
        +-- mysqli_sql_exception
        +-- OutOfBoundsException
        +-- OverflowException
        +-- PDOException
        +-- RangeException
        +-- UnderflowException
        +-- UnexpectedValueException

Example & Output

ArithmeticError

<?php

intdiv(PHP_INT_MIN, -1);

// output
// Fatal error: Uncaught ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer

DivisionByZeroError

<?php

$a = 3%0;

// output
// PHP Fatal error:  Uncaught DivisionByZeroError: Modulo by zero

$a = intdiv(3, 0); // 3/0 is not fire exception.

// output
// PHP Fatal error:  Uncaught DivisionByZeroError: Division by zero

AssertionError

<?php

ini_set('assert.exception', 1); //if without this, not exception but error

assert(2 < 1);

// output
// PHP Fatal error:  Uncaught AssertionError: assert(2 < 1) in...

ArgumentCountError

<?php

declare(strict_types=1); //if without this, not exception but error

$a = [1,2=>[3,4]];

count($a, COUNT_RECURSIVE, 'throw error');

// output
// PHP Fatal error:  Uncaught ArgumentCountError: count() expects at most 2 parameters, 3 given

TypeError

<?php

a('throw error');

function a(int $b) {}

// output
// PHP Fatal error:  Uncaught TypeError: Argument 1 passed to a() must be of the type int, string given

Runtime Exceptions

Name
Example

LogicException

PHP Throwable Tree
Introduction
Example & Output
ArithmeticError
DivisionByZeroError
AssertionError
ArgumentCountError
TypeError
Runtime Exceptions
LogicException.php