Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PHPの様々なエラー
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
uzulla
March 16, 2019
Programming
420
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHPの様々なエラー
2019/03/17 at hachioji.pm #75 LT
uzulla
March 16, 2019
More Decks by uzulla
See All by uzulla
ALL CODE BASE ARE BELONG TO STUDY
uzulla
30
7.8k
バイブスあるコーディングで ~PHP~ 便利ツールをつくるプラクティス
uzulla
1
600
PHPer's Guide to Daemon Crafting Taming and Summoning
uzulla
2
2.8k
似たもの同士のPerlとPHP
uzulla
1
320
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
240
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
340
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
240
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
3.4k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
6
1.5k
Other Decks in Programming
See All in Programming
ALB ログから Trace を気合で繋げる技術
fohte
7
880
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
470
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
140
信頼性の目標を誰も求めてない
shubox
0
500
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
100
Deep dive into the select statement (GopherCon UK)
jespino
0
170
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
1.1k
デプロイ直後のレイテンシスパイクを調べたら、 Railsの仕様にたどり着いた
nhsykym
0
110
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
190
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
240
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
270
Done Done
chrislema
186
16k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
880
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
440
Documentation Writing (for coders)
carmenintech
77
5.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
WCS-LA-2024
lcolladotor
0
820
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
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ͨ͠Βແࢹ͞Εͳ͍ͷͰɺ@׆༻͢ Δݹ͍ϥΠϒϥϦΛ͏࣌ҙʂ