Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHPの様々なエラー

uzulla
March 16, 2019

 PHPの様々なエラー

2019/03/17 at hachioji.pm #75 LT

uzulla

March 16, 2019
Tweet

More Decks by uzulla

Other Decks in Programming

Transcript

  1. Τϥʔͷେ·͔ͳ෼ྨʢཁग़యʣ » ໰౴ແ༻Ͱࢮ͵΍ͭ » Fatal Errors » Parse Error »

    ࢮ͵͚Ͳख౰͢Ε͹ࢮͳͳ͍΍ͭ » Recoverable Fatal Error » ख౰͠ͳͯ͘΋ࢮͳͳ͍΍ͭ » Warning » Noticeʢ౳
  2. E_ERROR (1<<0L) 1 E_WARNING (1<<1L) 2 E_PARSE (1<<2L) 4 E_NOTICE

    (1<<3L) 8 E_CORE_ERROR (1<<4L) 16 E_CORE_WARNING (1<<5L) 32 E_COMPILE_ERROR (1<<6L) 64 E_COMPILE_WARNING (1<<7L) 128 E_USER_ERROR (1<<8L) 256 E_USER_WARNING (1<<9L) 512 E_USER_NOTICE (1<<10L) 1024 E_STRICT (1<<11L) 2048 E_RECOVERABLE_ERROR (1<<12L) 4096 E_DEPRECATED (1<<13L) 8192 E_USER_DEPRECATED (1<<14L) 16384
  3. ஌Δʹ͸ register_shutdown_function(function () { $error = error_get_last(); if ( !is_array($error)

    || !( $error['type'] & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_PARSE | E_USER_ERROR) ) ) { return; // set_error_handelerͰर͍͑ͯΔ͸ͣͳͷͰແࢹ } // र͑ͳ͔ͬͨFATALͳΤϥʔ echo "{$error['type']}:{$error['message']}". " in {$error['file']}:{$error['line']}"; });
  4. ۩ମྫ <?php register_shutdown_function(function () { $error = error_get_last(); if (

    !is_array($error) || !( $error['type'] & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_PARSE | E_USER_ERROR) ) ) { return; } error_log("Fatal Error:{$error['type']}:{$error['message']}". " in {$error['file']}:{$error['line']}"); }); class b implements DateTimeInterface {} new b();
  5. ༨ஊ@ʹ͍ͭͯ » @Λ͚ͭͨࣜͷΤϥʔΛʮग़ྗ͠ͳ͍ʯʢ͚ͩʣ // $aม਺͕ແ͍࣌ php > echo @$a; //

    ΤϥʔͰͳ͍ɺNULLʹͳΔ php > echo $a; PHP Notice: Undefined variable: a in php shell code on line 1
  6. » @ͳΒFatalͰࢮͳͳ͍Θ͚Ͱ΋ͳ͘ʢࠂ஌ͳ͘ࢮ͵͕ʣ » @͸ݟ͚ͭͨΒʢཧ༝͕ͳ͚Ε͹ʣফ͠·͠ΐ͏ // ݹ୅ɺ͜͏͍͏ॻ͖ํ΋͋ͬͨͳ $id = @$_POST['id']; //

    ͍·ͳΒ͜͏͔ $id = $_POST['id'] ?? null; » ͳ͓ɺࣗલͰset_error_handlerͨ͠Βແࢹ͞Εͳ͍ͷͰɺ@׆༻͢ Δݹ͍ϥΠϒϥϦΛ࢖͏࣌͸஫ҙʂ