{"id":826,"date":"2025-08-04T19:23:36","date_gmt":"2025-08-04T10:23:36","guid":{"rendered":"https:\/\/nexive.tech\/?p=826"},"modified":"2025-08-04T19:23:36","modified_gmt":"2025-08-04T10:23:36","slug":"%e3%80%90%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%a7%a3%e8%aa%ac%e3%80%91php-%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%a0%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%8f%e3%83%b3%e3%83%89%e3%83%a9%e3%83%bc%e3%81%ae","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=826","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011PHP \u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u306e\u4f5c\u308a\u65b9"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP\u3067\u72ec\u81ea\u306e\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u51e6\u7406\u3092\u7d44\u307f\u8fbc\u3080\u65b9\u6cd5\u3092\u89e3\u8aac<\/li>\n\n\n\n<li><code>set_error_handler<\/code>\u3068<code>set_exception_handler<\/code>\u306e\u4f7f\u3044\u5206\u3051\u3092\u660e\u793a<\/li>\n\n\n\n<li>\u5b9f\u52d9\u5411\u3051\u306b\u30ed\u30b0\u51fa\u529b\u30fb\u4f8b\u5916\u5909\u63db\u30d1\u30bf\u30fc\u30f3\u307e\u3067\u30ab\u30d0\u30fc<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. PHP\u306e\u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>PHP\u306e\u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u3068\u306f\u3001\u30a8\u30e9\u30fc\u3084\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u969b\u306b\u3001\u72ec\u81ea\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u3001PHP\u306f\u30a8\u30e9\u30fc\u767a\u751f\u6642\u306b\u6a19\u6e96\u51fa\u529b\u3078\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3057\u307e\u3059\u304c\u3001\u672c\u756a\u74b0\u5883\u3067\u306f\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u8a18\u9332\u3084\u72ec\u81ea\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u306e\u51fa\u529b\u304c\u5fc5\u8981\u306b\u306a\u308b\u30b1\u30fc\u30b9\u304c\u591a\u304f\u3042\u308a\u307e\u3059\u3002\u3053\u3046\u3057\u305f\u30cb\u30fc\u30ba\u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u3001<code>set_error_handler<\/code>\u3084<code>set_exception_handler<\/code>\u3068\u3044\u3063\u305f\u95a2\u6570\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3089\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5168\u4f53\u3067\u7d71\u4e00\u7684\u306a\u30a8\u30e9\u30fc\u30ed\u30b0\u51e6\u7406\u3092\u884c\u3063\u305f\u308a\u3001\u91cd\u5927\u306a\u4f8b\u5916\u306e\u307f\u3092\u30e1\u30fc\u30eb\u901a\u77e5\u3059\u308b\u306a\u3069\u306e\u67d4\u8edf\u306a\u5bfe\u5fdc\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3068\u304f\u306b\u3001\u5b9f\u52d9\u306b\u304a\u3044\u3066\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5834\u9762\u3067\u6709\u52b9\u3067\u3059\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a8\u30e9\u30fc\u5185\u5bb9\u3068\u30b9\u30bf\u30c3\u30af\u30c8\u30ec\u30fc\u30b9\u3092\u30ed\u30b0\u306b\u8a18\u9332\u3057\u305f\u3044\u3068\u304d<\/li>\n\n\n\n<li>\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u5916\u3067\u72ec\u81ea\u306e\u4f8b\u5916\u51e6\u7406\u3092\u8a2d\u8a08\u3057\u305f\u3044\u3068\u304d<\/li>\n\n\n\n<li>\u901a\u77e5\u30fb\u30e2\u30cb\u30bf\u30ea\u30f3\u30b0\u3068\u306e\u9023\u643a\uff08Slack\u3084\u30e1\u30fc\u30eb\uff09\u3092\u7d44\u307f\u8fbc\u307f\u305f\u3044\u3068\u304d<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8a73\u7d30\u89e3\u8aac<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3-1. \u57fa\u672c\u7684\u306a\u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u306e\u69cb\u6587\u3068\u767b\u9332\u65b9\u6cd5<\/h3>\n\n\n\n<p>\u3082\u3063\u3068\u3082\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068\u3057\u3066\u3001<code>set_error_handler<\/code>\u95a2\u6570\u3092\u4f7f\u3044\u307e\u3059\u3002\u3053\u308c\u306fPHP\u306e\u8b66\u544a\u30fb\u6ce8\u610f\u30fb\u81f4\u547d\u7684\u3067\u306a\u3044\u30a8\u30e9\u30fc\uff08E_WARNING\u306a\u3069\uff09\u306b\u5bfe\u5fdc\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u95a2\u6570\u306e\u5b9a\u7fa9\nfunction myErrorHandler($errno, $errstr, $errfile, $errline) {\n    \/\/ \u30a8\u30e9\u30fc\u30ed\u30b0\u306b\u8a18\u9332\n    error_log(\"&#91;$errno&#93; $errstr in $errfile on line $errline\");\n    return true; \/\/ PHP\u306e\u65e2\u5b9a\u306e\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u3092\u7121\u52b9\u5316\n}\n\n\/\/ \u767b\u9332\nset_error_handler(\"myErrorHandler\");\n\n\/\/ \u5b9f\u884c\u4f8b\necho $undefinedVar; \/\/ \u672a\u5b9a\u7fa9\u5909\u6570\u30a2\u30af\u30bb\u30b9\uff1aE_NOTICE\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u95a2\u6570\u306e\u5b9a\u7fa9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">myErrorHandler<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$errno<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errstr<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errfile<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errline<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\">\/\/ \u30a8\u30e9\u30fc\u30ed\u30b0\u306b\u8a18\u9332<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">error_log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;&#91;<\/span><span style=\"color: #9CDCFE\">$errno<\/span><span style=\"color: #CE9178\">&#93; <\/span><span style=\"color: #9CDCFE\">$errstr<\/span><span style=\"color: #CE9178\"> in <\/span><span style=\"color: #9CDCFE\">$errfile<\/span><span style=\"color: #CE9178\"> on line <\/span><span style=\"color: #9CDCFE\">$errline<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">true<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ PHP\u306e\u65e2\u5b9a\u306e\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u3092\u7121\u52b9\u5316<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u767b\u9332<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">set_error_handler<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;myErrorHandler&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u5b9f\u884c\u4f8b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$undefinedVar<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u672a\u5b9a\u7fa9\u5909\u6570\u30a2\u30af\u30bb\u30b9\uff1aE_NOTICE<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001\u672a\u5b9a\u7fa9\u5909\u6570\u30a2\u30af\u30bb\u30b9\u6642\u306b\u30ab\u30b9\u30bf\u30e0\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u3001\u6a19\u6e96\u51fa\u529b\u306b\u306f\u8868\u793a\u3055\u308c\u305a\u30ed\u30b0\u8a18\u9332\u306e\u307f\u304c\u884c\u308f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3-2. \u4f8b\u5916\u51e6\u7406\u7528\uff1aset_exception_handler\u306e\u5229\u7528<\/h3>\n\n\n\n<p>\u81f4\u547d\u7684\u306a\u4f8b\u5916\uff08throw\u3055\u308c\u305f\u4f8b\u5916\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\u306b\u5bfe\u3057\u3066\u306f\u3001<code>set_exception_handler<\/code>\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u30ab\u30b9\u30bf\u30e0\u4f8b\u5916\u30cf\u30f3\u30c9\u30e9\u30fc\nfunction myExceptionHandler(Throwable $exception) {\n    error_log(\"Uncaught exception: \" . $exception->getMessage());\n}\n\n\/\/ \u767b\u9332\nset_exception_handler(\"myExceptionHandler\");\n\n\/\/ \u5b9f\u884c\u4f8b\nthrow new RuntimeException(\"\u610f\u56f3\u7684\u306a\u4f8b\u5916\");\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30ab\u30b9\u30bf\u30e0\u4f8b\u5916\u30cf\u30f3\u30c9\u30e9\u30fc<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">myExceptionHandler<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">Throwable<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$exception<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">error_log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;Uncaught exception: &quot;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$exception<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">getMessage<\/span><span style=\"color: #D4D4D4\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u767b\u9332<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">set_exception_handler<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;myExceptionHandler&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u5b9f\u884c\u4f8b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">throw<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">new<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">RuntimeException<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;\u610f\u56f3\u7684\u306a\u4f8b\u5916&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001RuntimeException\u304cthrow\u3055\u308c\u305f\u3068\u304d\u306b\u3001\u65e2\u5b9a\u306e\u51fa\u529b\u306f\u6291\u5236\u3055\u308c\u3001\u30ed\u30b0\u306b\u8a18\u9332\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3-3. \u30a8\u30e9\u30fc\u3092\u4f8b\u5916\u306b\u5909\u63db\u3059\u308b\uff08\u5b9f\u52d9\u3067\u3088\u304f\u4f7f\u308f\u308c\u308b\u30d1\u30bf\u30fc\u30f3\uff09<\/h3>\n\n\n\n<p>\u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u3067\u30a8\u30e9\u30fc\u3092\u4f8b\u5916\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\u3053\u308c\u306f\u7d71\u4e00\u7684\u306atry-catch\u306b\u3088\u308b\u4f8b\u5916\u51e6\u7406\u3092\u884c\u3044\u305f\u3044\u5834\u9762\u3067\u4fbf\u5229\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>set_error_handler(function($errno, $errstr, $errfile, $errline) {\n    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);\n});\n\ntry {\n    $x = 10 \/ 0; \/\/ Warning: Division by zero \u2192 \u4f8b\u5916\u306b\u5909\u63db\u3055\u308c\u308b\n} catch (ErrorException $e) {\n    echo \"\u4f8b\u5916\u3068\u3057\u3066\u6355\u6349: \" . $e->getMessage();\n}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #DCDCAA\">set_error_handler<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$errno<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errstr<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errfile<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errline<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">throw<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">new<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">ErrorException<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$errstr<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errno<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errfile<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">$errline<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">});<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">try<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$x<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">10<\/span><span style=\"color: #D4D4D4\"> \/ <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ Warning: Division by zero \u2192 \u4f8b\u5916\u306b\u5909\u63db\u3055\u308c\u308b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #C586C0\">catch<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #4EC9B0\">ErrorException<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$e<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u4f8b\u5916\u3068\u3057\u3066\u6355\u6349: &quot;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$e<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">getMessage<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u65b9\u6cd5\u306b\u3088\u308a\u3001\u8b66\u544a\u30ec\u30d9\u30eb\u306e\u30a8\u30e9\u30fc\u3082\u4f8b\u5916\u3068\u3057\u3066\u7d71\u4e00\u7684\u306b\u6271\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3-4. <code>register_shutdown_function<\/code>\u3068\u306e\u4f75\u7528\u306b\u3088\u308b\u81f4\u547d\u7684\u30a8\u30e9\u30fc\u5bfe\u5fdc<\/h3>\n\n\n\n<p><code>set_error_handler<\/code>\u3067\u306f\u30ad\u30e3\u30c3\u30c1\u3067\u304d\u306a\u3044<code>E_ERROR<\/code>\u306a\u3069\u306e\u81f4\u547d\u7684\u306a\u30a8\u30e9\u30fc\u306f\u3001<code>register_shutdown_function<\/code>\u3067\u5bfe\u5fdc\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>register_shutdown_function(function() {\n    $error = error_get_last();\n    if ($error &amp;&amp; $error&#91;'type'&#93; === E_ERROR) {\n        error_log(\"\u81f4\u547d\u7684\u30a8\u30e9\u30fc: {$error&#91;'message'&#93;} in {$error&#91;'file'&#93;} on line {$error&#91;'line'&#93;}\");\n    }\n});\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #DCDCAA\">register_shutdown_function<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$error<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">error_get_last<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #9CDCFE\">$error<\/span><span style=\"color: #D4D4D4\"> &amp;&amp; <\/span><span style=\"color: #9CDCFE\">$error<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #CE9178\">&#39;type&#39;<\/span><span style=\"color: #D4D4D4\">&#93; === E_ERROR) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #DCDCAA\">error_log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;\u81f4\u547d\u7684\u30a8\u30e9\u30fc: {<\/span><span style=\"color: #9CDCFE\">$error<\/span><span style=\"color: #CE9178\">&#91;&#39;message&#39;&#93;} in {<\/span><span style=\"color: #9CDCFE\">$error<\/span><span style=\"color: #CE9178\">&#91;&#39;file&#39;&#93;} on line {<\/span><span style=\"color: #9CDCFE\">$error<\/span><span style=\"color: #CE9178\">&#91;&#39;line&#39;&#93;}&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">});<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u3001\u6700\u5f8c\u306b\u767a\u751f\u3057\u305f\u81f4\u547d\u7684\u30a8\u30e9\u30fc\u3092\u30ed\u30b0\u306b\u8a18\u9332\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u3088\u304f\u3042\u308b\u30df\u30b9\u30fb\u8aa4\u89e3\u30fb\u843d\u3068\u3057\u7a74<\/h2>\n\n\n\n<p>PHP\u306e\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3067\u306f\u3001\u6b21\u306e\u3088\u3046\u306a\u8aa4\u89e3\u3084\u6ce8\u610f\u70b9\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u3001<code>set_error_handler<\/code>\u306f\u81f4\u547d\u7684\u306a\u30a8\u30e9\u30fc\uff08E_ERROR\u3001E_PARSE\u306a\u3069\uff09\u3092\u51e6\u7406\u3067\u304d\u306a\u3044\u70b9\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\u3053\u308c\u3089\u306f<code>register_shutdown_function<\/code>\u3067\u88dc\u5b8c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001<code>set_error_handler<\/code>\u5185\u3067<code>return false<\/code>\u3092\u8fd4\u3059\u3068\u3001PHP\u306e\u65e2\u5b9a\u306e\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u304c\u547c\u3070\u308c\u3001\u30a8\u30e9\u30fc\u304c\u753b\u9762\u306b\u51fa\u529b\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u30ed\u30b0\u8a18\u9332\u306e\u307f\u3092\u884c\u3044\u305f\u3044\u5834\u5408\u306f\u3001\u5fc5\u305a<code>true<\/code>\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u3055\u3089\u306b\u3001\u30ab\u30b9\u30bf\u30e0\u30cf\u30f3\u30c9\u30e9\u30fc\u306e\u4e2d\u3067\u518d\u5ea6\u4f8b\u5916\u3092\u6295\u3052\u308b\u5834\u5408\uff08\u4f8b\uff1aErrorException\uff09\u3001\u547c\u3073\u51fa\u3057\u5143\u306btry-catch\u69cb\u6587\u304c\u306a\u3044\u3068\u30b9\u30af\u30ea\u30d7\u30c8\u5168\u4f53\u304c\u7570\u5e38\u7d42\u4e86\u3059\u308b\u30ea\u30b9\u30af\u304c\u3042\u308b\u305f\u3081\u3001try-catch\u306e\u30b9\u30b3\u30fc\u30d7\u8a2d\u8a08\u3082\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<p>PHP\u306e\u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u306f\u3001\u5b9f\u52d9\u3067\u306e\u30ed\u30b0\u7ba1\u7406\u3084\u4f8b\u5916\u7d71\u5408\u51e6\u7406\u306b\u6b20\u304b\u305b\u306a\u3044\u6280\u8853\u3067\u3059\u3002<\/p>\n\n\n\n<p><code>set_error_handler<\/code>\u3084<code>set_exception_handler<\/code>\u3092\u6b63\u3057\u304f\u4f7f\u3044\u5206\u3051\u308b\u3053\u3068\u3067\u3001\u30a8\u30e9\u30fc\u3078\u306e\u67d4\u8edf\u306a\u5bfe\u5fdc\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u52a0\u3048\u3066\u3001<code>register_shutdown_function<\/code>\u3092\u4f75\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u81f4\u547d\u7684\u30a8\u30e9\u30fc\u3078\u306e\u5bfe\u5fdc\u3082\u88dc\u5b8c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u9069\u5207\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u8a2d\u8a08\u306f\u3001\u904b\u7528\u4e0a\u306e\u4fdd\u5b88\u6027\u3068\u30c8\u30e9\u30d6\u30eb\u5bfe\u5fdc\u306e\u8fc5\u901f\u5316\u306b\u3064\u306a\u304c\u308b\u91cd\u8981\u306a\u57fa\u76e4\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. PHP\u306e\u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u3068\u306f\uff1f PHP\u306e\u30ab\u30b9\u30bf\u30e0\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u30fc\u3068\u306f\u3001\u30a8\u30e9\u30fc\u3084\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u969b\u306b\u3001\u72ec\u81ea\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u4ed5\u7d44\u307f\u3067\u3059\u3002 \u901a\u5e38\u3001PHP\u306f\u30a8\u30e9\u30fc\u767a\u751f\u6642\u306b\u6a19\u6e96\u51fa\u529b\u3078\u30a8\u30e9\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":903,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[85],"tags":[],"class_list":["post-826","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=826"}],"version-history":[{"count":2,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/826\/revisions"}],"predecessor-version":[{"id":904,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/826\/revisions\/904"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/903"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}