{"id":46893,"date":"2024-12-02T10:03:44","date_gmt":"2024-12-02T02:03:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46893\/"},"modified":"2024-12-02T10:03:44","modified_gmt":"2024-12-02T02:03:44","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%bf%90%e8%a1%8c%e6%97%b6%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46893\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff1f<\/h1>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><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\u8fd0\u884c\u65f6\u9519\u8bef\uff1f\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u9519\u8bef\u5904\u7406\u673a\u5236\u6765\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u5305\u62ec\uff1aset_error_handler()\uff1a\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570\uff0c\u5b83\u63a5\u6536\u9519\u8bef\u7ea7\u522b\u3001\u9519\u8bef\u4fe1\u606f\u3001\u9519\u8bef\u6587\u4ef6\u548c\u9519\u8bef\u884c\u53f7\u4f5c\u4e3a\u53c2\u6570\u3002restore_error_handler()\uff1a\u8fd8\u539f\u4e4b\u524d\u7684\u9519\u8bef\u5904\u7406\u51fd\u6570\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729852694671b7516df927.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u8fd0\u884c\u65f6\u9519\u8bef\u6307\u5728\u4ee3\u7801\u6267\u884c\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684\u9519\u8bef\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u9664\u96f6\u9519\u8bef<\/li>\n<li>\u8bbf\u95ee\u672a\u58f0\u660e\u7684\u53d8\u91cf<\/li>\n<li>\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u5b58\u5728\u7684\u7c7b\u6216\u65b9\u6cd5<\/li>\n<\/ul>\n<p><strong>\u9519\u8bef\u5904\u7406\u673a\u5236<\/strong><\/p>\n<p>PHP \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u7528\u4e8e\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\u7684\u51fd\u6570\uff1a<\/p>\n<ul>\n<li><strong>set_error_handler()\uff1a<\/strong>\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u5904\u7406\u51fd\u6570<\/li>\n<li><strong>restore_error_handler()\uff1a<\/strong>\u8fd8\u539f\u4e4b\u524d\u7684\u9519\u8bef\u5904\u7406\u51fd\u6570<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528 <strong>set_error_handler()<\/strong> \u51fd\u6570\uff1a<\/p>\n<pre>&lt;?php\n\n\/\/ \u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570\nfunction my_error_handler($errno, $errstr, $errfile, $errline) {\n  echo \"Error: [$errno] $errstr in $errfile on line $errline\";\n}\n\n\/\/ \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570\nset_error_handler(\"my_error_handler\");\n\n\/\/ \u89e6\u53d1\u8fd0\u884c\u65f6\u9519\u8bef\necho $undefined_variable;\n\n?&gt;<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Error: [8] Undefined variable: undefined_variable in error_handling.php on line 15<\/pre>\n<p>\u5f53 <code>$undefined_variable<\/code> \u53d8\u91cf\u672a\u58f0\u660e\u65f6\uff0c\u5b83\u4f1a\u89e6\u53d1 <code>E_NOTICE<\/code> \u9519\u8bef\uff0c\u5e76\u7531\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570\u5904\u7406\u3002<\/p>\n<p><strong>\u5176\u4ed6\u7528\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570\u5916\uff0c<strong>set_error_handler()<\/strong> \u51fd\u6570\u8fd8\u53ef\u4ee5\u63a5\u6536\u4ee5\u4e0b\u53c2\u6570\uff1a<\/p>\n<ul>\n<li><strong>error_level\uff1a<\/strong>\u6307\u5b9a\u8981\u5904\u7406\u7684\u9519\u8bef\u7ea7\u522b<\/li>\n<li><strong>callback\uff1a<\/strong>\u6307\u5411\u9519\u8bef\u5904\u7406\u51fd\u6570\u7684\u533f\u540d\u51fd\u6570\u6216\u95ed\u5305<\/li>\n<\/ul>\n<p>\u6587\u4e2d\u5173\u4e8ephp,\u9519\u8bef\u5904\u7406\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff1f \u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898\u662f\u300aPHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff1f\u300b\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01 PHP \u63d0\u4f9b\u4e86\u9519\u8bef\u5904\u7406\u673a\u5236\u6765\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u5305\u62ec\uff1aset_error_handler()\uff1a\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570\uff0c\u5b83\u63a5\u6536\u9519\u8bef\u7ea7\u522b\u3001\u9519\u8bef\u4fe1\u606f\u3001\u9519\u8bef\u6587\u4ef6\u548c\u9519\u8bef\u884c\u53f7\u4f5c\u4e3a\u53c2\u6570\u3002restore_error_handler()\uff1a\u8fd8\u539f\u4e4b\u524d\u7684\u9519\u8bef\u5904\u7406\u51fd\u6570\u3002 PHP \u51fd\u6570\u5982\u4f55\u5904\u7406\u4ee3\u7801\u4e2d\u7684\u8fd0\u884c\u65f6\u9519\u8bef \u5728 PHP \u4e2d\uff0c\u8fd0\u884c\u65f6\u9519\u8bef\u6307\u5728\u4ee3\u7801\u6267\u884c\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684\u9519\u8bef\uff0c\u4f8b\u5982\uff1a \u9664\u96f6\u9519\u8bef \u8bbf\u95ee\u672a\u58f0\u660e\u7684\u53d8\u91cf \u5c1d\u8bd5\u4f7f\u7528\u4e0d\u5b58\u5728\u7684\u7c7b\u6216\u65b9\u6cd5 \u9519\u8bef\u5904\u7406\u673a\u5236 PHP \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u7528\u4e8e\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\u7684\u51fd\u6570\uff1a set_error_handler()\uff1a\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u7684\u9519\u8bef\u5904\u7406\u51fd\u6570 restore_error_handler()\uff1a\u8fd8\u539f\u4e4b\u524d\u7684\u9519\u8bef\u5904\u7406\u51fd\u6570 \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528 set_error_handler() \u51fd\u6570\uff1a &lt;?php \/\/ \u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570 function my_error_handler($errno, $errstr, $errfile, $errline) { echo &#8220;Error: [$errno] $errstr in $errfile on line $errline&#8221;; } \/\/ \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u51fd\u6570 set_error_handler(&#8220;my_error_handler&#8221;); \/\/ \u89e6\u53d1\u8fd0\u884c\u65f6\u9519\u8bef echo $undefined_variable; ?&gt; \u8f93\u51fa\uff1a Error: [8] Undefined variable: [&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-46893","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46893","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=46893"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46893\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}