{"id":47284,"date":"2024-12-02T09:17:57","date_gmt":"2024-12-02T01:17:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47284\/"},"modified":"2024-12-02T09:17:57","modified_gmt":"2024-12-02T01:17:57","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e4%bb%a3%e7%a0%81%e4%b8%ad%e7%9a%84%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47284\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p>PHP \u51fd\u6570\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u5176\u4e2d\u5305\u62ec\uff1aerror_get_last()\uff1a\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u8bed\u6cd5\u9519\u8bef\u7684\u4fe1\u606f\u3002set_error_handler()\uff1a\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8bed\u6cd5\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u3002register_shutdown_function()\uff1a\u5728\u811a\u672c\u6b63\u5e38\u5b8c\u6210\u6216\u7ec8\u6b62\u540e\u89e6\u53d1\u81ea\u5b9a\u4e49\u51fd\u6570\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729908745671c5009caa37.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p><strong>\u8bed\u6cd5\u9519\u8bef<\/strong>\u662f\u4ee3\u7801\u4e2d\u4efb\u4f55\u4e0d\u7b26\u5408 PHP \u8bed\u8a00\u89c4\u8303\u7684\u9519\u8bef\u3002\u5f53 PHP \u89e3\u6790\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\u3002\u5982\u679c\u53d1\u73b0\u4efb\u4f55\u9519\u8bef\uff0c\u5b83\u4f1a\u53d1\u51fa<strong>\u9519\u8bef\u6d88\u606f<\/strong>\u5e76\u505c\u6b62\u6267\u884c\u3002<\/p>\n<p><strong>\u8bed\u6cd5\u9519\u8bef\u7684\u7c7b\u578b<\/strong><\/p>\n<p>PHP \u4e2d\u6709\u8bb8\u591a\u7c7b\u578b\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u672a\u95ed\u5408\u5f15\u53f7\u6216\u82b1\u62ec\u53f7<\/strong><\/li>\n<li><strong>\u7f3a\u5c11\u5206\u53f7<\/strong><\/li>\n<li><strong>\u65e0\u6548\u7684\u51fd\u6570\u6216\u7c7b\u540d<\/strong><\/li>\n<li><strong>\u65e0\u6548\u7684\u64cd\u4f5c\u7b26<\/strong><\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u5904\u7406\u8bed\u6cd5\u9519\u8bef<\/strong><\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u51e0\u4e2a\u51fd\u6570\u6765\u5904\u7406\u8bed\u6cd5\u9519\u8bef\uff1a<\/p>\n<ul>\n<li><strong>error_get_last()\uff1a<\/strong>\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u8bed\u6cd5\u9519\u8bef\u7684\u4fe1\u606f\u3002<\/li>\n<li><strong>set_error_handler()\uff1a<\/strong>\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8bed\u6cd5\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u3002<\/li>\n<li><strong>register_shutdown_function()\uff1a<\/strong>\u5728\u811a\u672c\u6b63\u5e38\u5b8c\u6210\u6216\u7ec8\u6b62\u540e\u89e6\u53d1\u81ea\u5b9a\u4e49\u51fd\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u8bed\u6cd5\u9519\u8bef\u7684\u5b9e\u9645\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;?php\n\n\/\/ \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\nset_error_handler(function ($errno, $errstr, $errfile, $errline) {\n    \/\/ \u68c0\u67e5\u662f\u5426\u662f\u8bed\u6cd5\u9519\u8bef\n    if ($errno === E_PARSE) {\n        \/\/ \u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\n        error_log(\"\u9519\u8bef\uff1a $errstr \u5728 $errfile \u884c $errline\");\n    }\n});\n\n\/\/ \u89e6\u53d1\u8bed\u6cd5\u9519\u8bef\n$a = \"test\" b; \/\/ \u7f3a\u5c11\u5206\u53f7\n\n\/\/ \u4f7f\u7528 error_get_last() \u83b7\u53d6\u9519\u8bef\u4fe1\u606f\n$error = error_get_last();\necho $error['message']; \/\/ \u8f93\u51fa\u9519\u8bef\u6d88\u606f\n\n\/\/ \u6ce8\u518c\u4e00\u4e2a\u5173\u95ed\u51fd\u6570\uff0c\u5728\u811a\u672c\u7ec8\u6b62\u65f6\u89e6\u53d1\nregister_shutdown_function(function () {\n    \/\/ \u67e5\u770b\u662f\u5426\u6709\u4efb\u4f55\u8bed\u6cd5\u9519\u8bef\n    $error = error_get_last();\n    if ($error) {\n        echo \"\u811a\u672c\u7ec8\u6b62\uff0c\u539f\u56e0\uff1a\u8bed\u6cd5\u9519\u8bef\";\n    }\n});<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53\u89e6\u53d1\u8bed\u6cd5\u9519\u8bef\u65f6\uff0c\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u4f1a\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u3002error_get_last() \u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u9519\u8bef\u6d88\u606f\uff0c\u800c register_shutdown_function() \u51fd\u6570\u7528\u4e8e\u5728\u811a\u672c\u7ec8\u6b62\u65f6\u68c0\u67e5\u662f\u5426\u6709\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aPHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\u300aPHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01 PHP \u51fd\u6570\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u5176\u4e2d\u5305\u62ec\uff1aerror_get_last()\uff1a\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u8bed\u6cd5\u9519\u8bef\u7684\u4fe1\u606f\u3002set_error_handler()\uff1a\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8bed\u6cd5\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u3002register_shutdown_function()\uff1a\u5728\u811a\u672c\u6b63\u5e38\u5b8c\u6210\u6216\u7ec8\u6b62\u540e\u89e6\u53d1\u81ea\u5b9a\u4e49\u51fd\u6570\u3002 PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f \u7b80\u4ecb \u8bed\u6cd5\u9519\u8bef\u662f\u4ee3\u7801\u4e2d\u4efb\u4f55\u4e0d\u7b26\u5408 PHP \u8bed\u8a00\u89c4\u8303\u7684\u9519\u8bef\u3002\u5f53 PHP \u89e3\u6790\u4ee3\u7801\u65f6\uff0c\u5b83\u4f1a\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\u3002\u5982\u679c\u53d1\u73b0\u4efb\u4f55\u9519\u8bef\uff0c\u5b83\u4f1a\u53d1\u51fa\u9519\u8bef\u6d88\u606f\u5e76\u505c\u6b62\u6267\u884c\u3002 \u8bed\u6cd5\u9519\u8bef\u7684\u7c7b\u578b PHP \u4e2d\u6709\u8bb8\u591a\u7c7b\u578b\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u5305\u62ec\uff1a \u672a\u95ed\u5408\u5f15\u53f7\u6216\u82b1\u62ec\u53f7 \u7f3a\u5c11\u5206\u53f7 \u65e0\u6548\u7684\u51fd\u6570\u6216\u7c7b\u540d \u65e0\u6548\u7684\u64cd\u4f5c\u7b26 \u5982\u4f55\u5904\u7406\u8bed\u6cd5\u9519\u8bef PHP \u63d0\u4f9b\u4e86\u51e0\u4e2a\u51fd\u6570\u6765\u5904\u7406\u8bed\u6cd5\u9519\u8bef\uff1a error_get_last()\uff1a\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u8bed\u6cd5\u9519\u8bef\u7684\u4fe1\u606f\u3002 set_error_handler()\uff1a\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8bed\u6cd5\u9519\u8bef\u5904\u7406\u7a0b\u5e8f\u3002 register_shutdown_function()\uff1a\u5728\u811a\u672c\u6b63\u5e38\u5b8c\u6210\u6216\u7ec8\u6b62\u540e\u89e6\u53d1\u81ea\u5b9a\u4e49\u51fd\u6570\u3002 \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u5904\u7406\u8bed\u6cd5\u9519\u8bef\u7684\u5b9e\u9645\u793a\u4f8b\uff1a &lt;?php \/\/ \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u7a0b\u5e8f set_error_handler(function ($errno, $errstr, $errfile, $errline) { \/\/ \u68c0\u67e5\u662f\u5426\u662f\u8bed\u6cd5\u9519\u8bef if ($errno === E_PARSE) { \/\/ \u8bb0\u5f55\u9519\u8bef\u4fe1\u606f error_log(&#8220;\u9519\u8bef\uff1a $errstr \u5728 $errfile \u884c $errline&#8221;); } }); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47284","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47284"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47284\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}