Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHPの様々なエラー
Search
uzulla
March 16, 2019
Programming
0
180
PHPの様々なエラー
2019/03/17 at hachioji.pm #75 LT
uzulla
March 16, 2019
Tweet
Share
More Decks by uzulla
See All by uzulla
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
89
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
160
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
100
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
1.9k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
870
PHPerが ISUCONでやるべき事
uzulla
1
760
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
210
test is not a job
uzulla
1
470
あなたのPHPアプリ、ログはでてますか?あるいはログをだしてますか? / Are you writing a log? Or just out a log?
uzulla
17
7.4k
Other Decks in Programming
See All in Programming
C#/.NETのこれまでのふりかえり
tomokusaba
1
170
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
270
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
200
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.9k
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
160
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.8k
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
1k
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
140
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
450
僕がつくった48個のWebサービス達
yusukebe
18
17k
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
170
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Designing for Performance
lara
604
68k
Measuring & Analyzing Core Web Vitals
bluesmoon
2
51
GraphQLとの向き合い方2022年版
quramy
43
13k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
What's in a price? How to price your products and services
michaelherold
243
12k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Transcript
PHPͷ༷ʑͳΤϥʔ hachiojipm #75 2019/03/16 @uzulla
લఏ » ඞͣ͠·͠ΐ͏ɻ error_reporting(E_ALL);
PHPͷΤϥʔ » ࣗ༝ͳՕॴͰͷΩϟον͔ͳΓࠔ͕ͩɺϋϯυϥΛઃఆͰ͖Δ » PHP 7ʹͳΓɺେମ͕ʮErrorʯͱ͍͏Exceptionʹͳͬͨ » Ωϟον͠ͳ͍ͱ(ຊͷ)Errorʹม͞ΕΔ » ʢঘɺྫ֎Ωϟον͠ͳ͚Ε͍ͣΕʹͤΑࢮ͵ʣ
» શ෦͕ྫ֎Ͱͳ͍͕ɺେମThrowableΛΩϟον͢ΕΑ͍ » ͔͠͠Թނ৽ɺൿͷλϨΛ͔͖ճͧ͢ɻ
Τϥʔͷେ·͔ͳྨʢཁग़యʣ » ແ༻Ͱࢮ͵ͭ » Fatal Errors » Parse Error »
ࢮ͵͚Ͳख͢Εࢮͳͳ͍ͭ » Recoverable Fatal Error » ख͠ͳͯ͘ࢮͳͳ͍ͭ » Warning » Noticeʢ
recoverable ͱ… » Τϥʔʢྫ֎Έ͍ͨͳͷʣΛΩϟονͯ͠ѲΓͭͿͤࢮͳͳ͍ » ޙड़
ྨΛ͞Βʹࡉʹ
Fatal, Parse(Syntax) Error » E_ERROR » E_CORE_ERROR » E_COMPILE_ERROR »
E_USER_ERROR » E_PARSE
Recoverable Fatal Error » E_RECOVERABLE_ERROR
Warning » E_WARNING » E_CORE_WARNING » E_COMPILE_WARNING » E_USER_WARNING
Notice ͳͲ » E_DEPRECATED » E_USER_DEPRECATED » E_NOTICE » E_USER_NOTICE
» (E_STRICT)
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
ͰҾ͖ى͜͠·͠ΐ͏
E_ERROR » DateTimeInterfaceΛΠϯϓϦ͠Α͏ͱ͢ΔͳͲ class b implements DateTimeInterface { } new
b();
ଈࢮ͢ΔͷͰ » ʢޙड़ͷʣset_error_handerݺΕͳ͍ » ͳʹͰ͖ͳ͍ɺඞͣࢮ͵ » ͔͠͠ɺΤϥʔͷऔΓ͘Β͍Ͱ͖Δ
Δʹ 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']}"; });
۩ମྫ <?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();
» Կݴ͏͚Ͳɺٹ͑ΔΘ͚Ͱͳ͍ » ۤͷϩάͨ͠ΓɺΤϥʔը໘Λग़ͨ͠Γఔ » ૹ৴ͨ͠σʔλ͕ͲΔΘ͚Ͱͳ͍ͷͰɺΰϛͷͳ͍ΩϨΠͳΤ ϥʔը໘Λग़ͨ͢Ίʹग़ྗͳͲΛOutput bufferingͯ͠ૹ৴͠ͳ ͍Ͱ͓͘͜ͱ »
https://uzulla.hateblo.jp/entry/2019/03/13/200820 » ͋·Γڽͬͨࣄ͠ͳ͍΄͏͕ແʢ͢Ͱʹ͓͔͍͠ঢ়ଶ͔ͩΒ Ͷʂʣ
E_CORE_ERROR » vmपΓͷΤϥʔ…ൃੜͤ͞Δํ๏͕Θ͔ΒΜ » odbcʹ͋Γͦ͏ʢ͔͠͠odbcΛ͏ࣄͳͲ͋Δͷ͔…ʁ » (ྑ͍αϯϓϧίʔυͭ͘Εͳ͔ͬͨ!)
E_COMPILE_ERROR » ఆٛࡁΈͷΫϥεΛએݴ͢ΕΑ͍ class DateTime{}
E_USER_ERROR » ࣗͰ͛ΒΕΔ » trigger_error trigger_error("test error", E_USER_ERROR);
E_PARSE » จ๏ؒҧ͑ΔͳͲ » ࢮ͵͠ɺ࠷ॳͷϑΝΠϧͩͱregister_shutdown_functionݺΕͳ͍ <?php require("bad.php"); // register_shutdown_functionݺΕΔ ...
<?php if if (1){} // ͳʹͰ͖ͣଈࢮ
ҙɺEvalʹ͍ͭͯ » evalE_PARSE͕ൃੜ͢Δͷ͕ͩɺྫ֎ͷΩϟονΛ͠ͳ͍߹ͷΈੜ·ΕΔ » ͳ͓ɺྫ֎ΛΩϟον͠ͳ͍ͱFatal Errorѻ͍ʹͳΓɺࢮ͵ɻ » PHPϜζΧγΠωʔ // ࢮͳͳ͍ʢ͠ɺѲΓ௵ͤΤϥʔͳ͍ʣ
try{ eval("if if(1){};"); }catch(\Throwable $e){ } // Uncaught ExceptionͰ͝ͱࢮ͵ eval("if if(1){};");
E_RECOVERABLE_ERROR » ΦϒδΣΫτΛແͳΩϟετ͢ΔͳͲͯ͠ൃੜͰ͖Δ » ࢮ͵…͕ɺ෮׆Ͱ͖Δ echo function() {};
ͨͱ͑͜ΕΛೖΕΔͱɺऴྃ͠ͳ͍ » NoticeؚΊɺ͋ΒΏΔΤϥʔʢFatalআ͘ʣ͕ඈͼࠐΉ » Notice͘ΔͷͰɺ͜͜ͰExit͢ΔͱNoticeڐ͞ͳ͍ࣄ͕Ͱ͖Δ ʢ෭࡞༻తϝϦοτʢओ؍ʣʣ set_error_handler(function ($type, $message, $file,
$line) { error_log("Error: {$type}:{$message} in {$file}:{$line}"); // ͜͜Ͱ exit͠ͳ͍ͱɺ࣮ͬͯߦ͕ଓ͘ // ྫ֎ͷѲΓͭͿ͠ͷΑ͏ͳͷ });
E_WARNING » ͢ͰʹϘσΟ͕ૹ৴։࢝͞Ε͍ͯΔͷʹɺϔομʔΛ͓͘Ζ͏ͱͨ͠ ࣌ͳͲ » ࢮͳͳ͍ɺͷ͕ࠔΔɻʢͷͰɺલड़ͷςΫΛ͏ͱΑ͍ࣄʣ header("X-MY-HEADER: hoge"); echo "hoge";
session_start();
E_CORE_WARNING » ଘࡏ͠ͳ͍֦ுΛphp.iniͰࢦఆ͢Δ » Γαϯϓϧίʔυ͕͍͍ײ͡ͷ͕ͳ͔ͬͨͷͰলུ
E_COMPILE_WARNING » /*Λด͡ͳ͍ͳͲ » ιʔείʔυͷจࣈίʔυΛ͓͔͘͢͠ΔͳͲ » ͜ΕɺWarnͱ͍͏͔Syntax ErrorͰͳ͍ͷ͔ͱ… <php /*
E_USER_WARNING » ࣗͰtrigger͢Δ trigger_error("test error", E_USER_WARNING);
E_DEPRECATED » ඇਪͷؔʢڍಈʣΛͤ͞Δ » error_reporting(E_ALL)ͯ͠ͳ͍ͱͰͳ͍ error_reporting(E_ALL); define("SomeThing", "is", true);
E_USER_DEPRECATED » ࣗͰ͛Δ » error_reporting(E_ALL)ͯ͠ͳ͍ͱͰͳ͍ trigger_error("test error", E_USER_DEPRECATED);
E_NOTICE » ະఆٛมʹ৮Δɺଘࡏ͠ͳ͍ൣғͷྻʹ৮Δ » error_reporting(E_ALL)ͯ͠ͳ͍ͱͰͳ͍ echo $undefined;
E_USER_NOTICE » ࣗͰ͛Δ » error_reporting(E_ALL)ͯ͠ͳ͍ͱͰͳ͍ trigger_error("test error", E_USER_DEPRECATED);
(E_STRICT) » PHP5·Ͱ͔͠ͳ͍ɺ7Ͱͳ͘ͳͬͨ(ଞʹҠಈ͞Εͨ) » ܧঝͨ͠ΫϥεϝιουͷϑΟϯΨʔϓϦϯτ͕ҧ͏ͱ͔ʢҾ͕ม ΘΔͱ͔ʣ
·ͱΊ » Ή͔͍ͣ͠ » ൿͷλϨ͕Δʢόʔδϣϯ্͕͕Δͱඍົʹʣ » ωοτʹʢࣗΛؚΊͯʣӕ͕ଟ͍ͷͰɺݕূͨ͠Γɺͨ·ʹλϨ Λ͔͖·ͥͳ͍ͱ͍͚ͳ͍ʢࠓ͔͖ࠞͥͨΒؒҧͬͯͨ…ʣ » ϏοτͷฒͼΛͳ͕Ί͍ͯΔͱɺ૿ઃͷྺ࢙Λײ͡ΒΕΔ
» ·͋PHPͳͷͰͶʂ
༨ஊ@ʹ͍ͭͯ » @Λ͚ͭͨࣜͷΤϥʔΛʮग़ྗ͠ͳ͍ʯʢ͚ͩʣ // $aม͕ແ͍࣌ php > echo @$a; //
ΤϥʔͰͳ͍ɺNULLʹͳΔ php > echo $a; PHP Notice: Undefined variable: a in php shell code on line 1
» @ͳΒFatalͰࢮͳͳ͍Θ͚Ͱͳ͘ʢࠂͳ͘ࢮ͵͕ʣ » @ݟ͚ͭͨΒʢཧ༝͕ͳ͚Εʣফ͠·͠ΐ͏ // ݹɺ͜͏͍͏ॻ͖ํ͋ͬͨͳ $id = @$_POST['id']; //
͍·ͳΒ͜͏͔ $id = $_POST['id'] ?? null; » ͳ͓ɺࣗલͰset_error_handlerͨ͠Βແࢹ͞Εͳ͍ͷͰɺ@׆༻͢ Δݹ͍ϥΠϒϥϦΛ͏࣌ҙʂ