{"id":48424,"date":"2024-12-02T16:38:18","date_gmt":"2024-12-02T08:38:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48424\/"},"modified":"2024-12-02T16:38:18","modified_gmt":"2024-12-02T08:38:18","slug":"%e6%b7%b1%e5%85%a5%e5%89%96%e6%9e%90php%e5%87%bd%e6%95%b0%e7%9a%84%e9%94%99%e8%af%af%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48424\/","title":{"rendered":"\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b<\/h1>\n<p>\u76ee\u524d\u7c73\u4e91\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u4e86\uff0c\u81ea\u5df1\u5728\u521d\u6b21\u9605\u8bfb\u8fd9\u4e9b\u6587\u7ae0\u4e2d\uff0c\u4e5f\u89c1\u8bc6\u5230\u4e86\u5f88\u591a\u5b66\u4e60\u601d\u8def\uff1b\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b\u300b<\/span>\uff0c\u4e5f\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u5982\u679c\u9605\u8bfb\u5b8c\u540e\u771f\u7684\u5bf9\u4f60\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce\u52a8\u52a8\u624b\u6307\uff0c\u8bc4\u8bba\u7559\u8a00\u5e76\u5206\u4eab~<\/p>\n<p>PHP \u51fd\u6570\u8fd4\u56de\u7684\u9519\u8bef\u7c7b\u578b\u5305\u62ec\uff1aE_ERROR\uff1a\u8bed\u6cd5\u9519\u8befE_WARNING\uff1a\u8fd0\u884c\u65f6\u9519\u8befE_NOTICE\uff1a\u975e\u81f4\u547d\u6027\u95ee\u9898E_STRICT\uff1a\u4e25\u683c\u8b66\u544aE_DEPRECATED\uff1a\u4e0d\u63a8\u8350\u4f7f\u7528\u7684\u51fd\u6570\u6216\u8bed\u6cd5<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730028046671e220e4f5a4.jpg\" class=\"aligncenter\" title=\"\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b\u63d2\u56fe\" alt=\"\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6df1\u5165\u5256\u6790 PHP \u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u4e0d\u540c\u7684\u9519\u8bef\u7c7b\u578b\u4ee5\u6307\u793a\u6267\u884c\u7ed3\u679c\u3002\u7406\u89e3\u8fd9\u4e9b\u9519\u8bef\u7c7b\u578b\u5bf9\u4e8e\u8c03\u8bd5\u548c\u7f16\u5199\u5065\u58ee\u7684\u4ee3\u7801\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p><strong>\u9519\u8bef\u7c7b\u578b<\/strong><\/p>\n<p>PHP \u51fd\u6570\u8fd4\u56de\u4ee5\u4e0b\u9519\u8bef\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li><strong>E_ERROR\uff1a<\/strong>\u8bed\u6cd5\u9519\u8bef\u3002<\/li>\n<li><strong>E_WARNING\uff1a<\/strong>\u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u4f8b\u5982\u65e0\u6cd5\u6253\u5f00\u6587\u4ef6\u3002<\/li>\n<li><strong>E_NOTICE\uff1a<\/strong>\u975e\u81f4\u547d\u6027\u95ee\u9898\uff0c\u4f8b\u5982\u53d8\u91cf\u672a\u521d\u59cb\u5316\u3002<\/li>\n<li><strong>E_STRICT\uff1a<\/strong>\u4e25\u683c\u8b66\u544a\uff0c\u7528\u4e8e\u53ef\u80fd\u5bfc\u81f4\u672a\u6765\u9519\u8bef\u3002<\/li>\n<li><strong>E_DEPRECATED\uff1a<\/strong>\u4e0d\u63a8\u8350\u4f7f\u7528\u7684\u51fd\u6570\u6216\u8bed\u6cd5\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u51fd\u6570\uff1a<\/p>\n<pre>function divideNumbers($num1, $num2)\n{\n    if ($num2 == 0) {\n        trigger_error('Division by zero is not allowed', E_ERROR);\n    }\n    return $num1 \/ $num2;\n}<\/pre>\n<p>\u8c03\u7528\u6b64\u51fd\u6570\u65f6\u53ef\u80fd\u8fd4\u56de\u4ee5\u4e0b\u9519\u8bef\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\u5982\u679c <code>$num2<\/code> \u4e3a 0\uff0c\u5219\u51fd\u6570\u4f1a\u89e6\u53d1\u4e00\u4e2a <strong>E_ERROR<\/strong>\uff0c\u56e0\u4e3a\u9664\u4ee5 0 \u662f\u8bed\u6cd5\u9519\u8bef\u3002<\/li>\n<li>\u5982\u679c <code>$num1<\/code> \u6216 <code>$num2<\/code> \u672a\u521d\u59cb\u5316\uff0c\u5219\u51fd\u6570\u4f1a\u4ea7\u751f <strong>E_NOTICE<\/strong>\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u53d8\u91cf\u672a\u58f0\u660e\u3002<\/li>\n<li>\u5982\u679c <code>$num2<\/code> \u4e3a\u4e00\u4e2a\u975e\u96f6\u503c\uff0c\u4f46\u5b83\u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u5219\u51fd\u6570\u4f1a\u89e6\u53d1 <strong>E_WARNING<\/strong>\uff0c\u56e0\u4e3a\u8be5\u51fd\u6570\u671f\u671b <code>$num2<\/code> \u4e3a\u4e00\u4e2a\u6570\u5b57\u3002<\/li>\n<\/ul>\n<p><strong>\u5904\u7406\u9519\u8bef<\/strong><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 <code>trigger_error()<\/code> \u51fd\u6570\u5f15\u53d1\u9519\u8bef\uff0c\u5e76\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528 <code>set_error_handler()<\/code> \u51fd\u6570\u5904\u7406\u9519\u8bef\u3002<\/p>\n<pre>function errorHandler($errno, $errstr, $errfile, $errline)\n{\n    switch ($errno) {\n        case E_ERROR:\n            echo 'Fatal error: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline;\n            exit;\n        case E_WARNING:\n            echo 'Warning: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline;\n            break;\n        case E_NOTICE:\n            echo 'Notice: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline;\n            break;\n    }\n}\n\nset_error_handler('errorHandler');<\/pre>\n<p>\u8fd9\u5c06\u6307\u793a PHP \u8c03\u7528 <code>errorHandler<\/code> \u51fd\u6570\u5e76\u6839\u636e\u9519\u8bef\u7c7b\u578b\u6253\u5370\u81ea\u5b9a\u4e49\u6d88\u606f\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b \u76ee\u524d\u7c73\u4e91\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u4e86\uff0c\u81ea\u5df1\u5728\u521d\u6b21\u9605\u8bfb\u8fd9\u4e9b\u6587\u7ae0\u4e2d\uff0c\u4e5f\u89c1\u8bc6\u5230\u4e86\u5f88\u591a\u5b66\u4e60\u601d\u8def\uff1b\u90a3\u4e48\u672c\u6587\u300a\u6df1\u5165\u5256\u6790php\u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b\u300b\uff0c\u4e5f\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u5982\u679c\u9605\u8bfb\u5b8c\u540e\u771f\u7684\u5bf9\u4f60\u5b66\u4e60\u6587\u7ae0\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce\u52a8\u52a8\u624b\u6307\uff0c\u8bc4\u8bba\u7559\u8a00\u5e76\u5206\u4eab~ PHP \u51fd\u6570\u8fd4\u56de\u7684\u9519\u8bef\u7c7b\u578b\u5305\u62ec\uff1aE_ERROR\uff1a\u8bed\u6cd5\u9519\u8befE_WARNING\uff1a\u8fd0\u884c\u65f6\u9519\u8befE_NOTICE\uff1a\u975e\u81f4\u547d\u6027\u95ee\u9898E_STRICT\uff1a\u4e25\u683c\u8b66\u544aE_DEPRECATED\uff1a\u4e0d\u63a8\u8350\u4f7f\u7528\u7684\u51fd\u6570\u6216\u8bed\u6cd5 \u6df1\u5165\u5256\u6790 PHP \u51fd\u6570\u7684\u9519\u8bef\u7c7b\u578b \u5728 PHP \u4e2d\uff0c\u51fd\u6570\u53ef\u4ee5\u8fd4\u56de\u4e0d\u540c\u7684\u9519\u8bef\u7c7b\u578b\u4ee5\u6307\u793a\u6267\u884c\u7ed3\u679c\u3002\u7406\u89e3\u8fd9\u4e9b\u9519\u8bef\u7c7b\u578b\u5bf9\u4e8e\u8c03\u8bd5\u548c\u7f16\u5199\u5065\u58ee\u7684\u4ee3\u7801\u81f3\u5173\u91cd\u8981\u3002 \u9519\u8bef\u7c7b\u578b PHP \u51fd\u6570\u8fd4\u56de\u4ee5\u4e0b\u9519\u8bef\u7c7b\u578b\uff1a E_ERROR\uff1a\u8bed\u6cd5\u9519\u8bef\u3002 E_WARNING\uff1a\u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u4f8b\u5982\u65e0\u6cd5\u6253\u5f00\u6587\u4ef6\u3002 E_NOTICE\uff1a\u975e\u81f4\u547d\u6027\u95ee\u9898\uff0c\u4f8b\u5982\u53d8\u91cf\u672a\u521d\u59cb\u5316\u3002 E_STRICT\uff1a\u4e25\u683c\u8b66\u544a\uff0c\u7528\u4e8e\u53ef\u80fd\u5bfc\u81f4\u672a\u6765\u9519\u8bef\u3002 E_DEPRECATED\uff1a\u4e0d\u63a8\u8350\u4f7f\u7528\u7684\u51fd\u6570\u6216\u8bed\u6cd5\u3002 \u5b9e\u6218\u6848\u4f8b \u8003\u8651\u4ee5\u4e0b\u51fd\u6570\uff1a function divideNumbers($num1, $num2) { if ($num2 == 0) { trigger_error(&#8216;Division by zero is not allowed&#8217;, E_ERROR); } return $num1 \/ $num2; } \u8c03\u7528\u6b64\u51fd\u6570\u65f6\u53ef\u80fd\u8fd4\u56de\u4ee5\u4e0b\u9519\u8bef\u7c7b\u578b\uff1a \u5982\u679c $num2 \u4e3a 0\uff0c\u5219\u51fd\u6570\u4f1a\u89e6\u53d1\u4e00\u4e2a E_ERROR\uff0c\u56e0\u4e3a\u9664\u4ee5 0 \u662f\u8bed\u6cd5\u9519\u8bef\u3002 \u5982\u679c $num1 \u6216 $num2 \u672a\u521d\u59cb\u5316\uff0c\u5219\u51fd\u6570\u4f1a\u4ea7\u751f [&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-48424","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48424","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=48424"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48424\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}