{"id":48232,"date":"2024-12-02T12:04:51","date_gmt":"2024-12-02T04:04:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48232\/"},"modified":"2024-12-02T12:04:51","modified_gmt":"2024-12-02T04:04:51","slug":"%e6%8a%9b%e5%87%ba%e5%bc%82%e5%b8%b8%e6%97%b6%ef%bc%8cphp-%e5%a6%82%e4%bd%95%e8%ae%b0%e5%bd%95%e5%a0%86%e6%a0%88%e8%b7%9f%e8%b8%aa%e4%bf%a1%e6%81%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48232\/","title":{"rendered":"\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p>PHP \u4e2d\u53ef\u4ee5\u901a\u8fc7 printStackTrace() \u65b9\u6cd5\u83b7\u53d6\u5f02\u5e38\u5806\u6808\u8ddf\u8e2a\uff0c\u8bb0\u5f55\u4e86\u4ece\u5f02\u5e38\u629b\u51fa\u70b9\u5230\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u70b9\u7684\u8c03\u7528\u94fe\u4fe1\u606f\uff0c\u5305\u62ec\u51fd\u6570\u540d\u79f0\u3001\u6587\u4ef6\u8def\u5f84\u548c\u884c\u53f7\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730003316671dc174c0784.jpg\" class=\"aligncenter\" title=\"\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f\u63d2\u56fe\" alt=\"\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u4e2d\u5f02\u5e38\u5806\u6808\u8ddf\u8e2a\u8bb0\u5f55\uff1a\u5165\u95e8\u6307\u5357<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u5f53\u629b\u51fa\u5f02\u5e38\u65f6\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u8bb0\u5f55\u4e00\u4e2a\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\u3002\u8be5\u4fe1\u606f\u6355\u83b7\u4e86\u5f02\u5e38\u53d1\u751f\u65f6\u7684\u8c03\u7528\u94fe\uff0c\u5bf9\u4e8e\u8c03\u8bd5\u548c\u7406\u89e3\u9519\u8bef\u5f02\u5e38\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/p>\n<p><strong>\u4ec0\u4e48\u662f\u5806\u6808\u8ddf\u8e2a\uff1f<\/strong><\/p>\n<p>\u5806\u6808\u8ddf\u8e2a\u662f\u4e00\u7cfb\u5217\u5e27\uff08\u4e5f\u79f0\u4e3a\u5806\u6808\u5e27\uff09\uff0c\u6bcf\u4e2a\u5e27\u90fd\u5305\u542b\u6709\u5173\u8c03\u7528\u51fd\u6570\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u51fd\u6570\u540d\u79f0\u3001\u6587\u4ef6\u8def\u5f84\u548c\u884c\u53f7\u3002\u5b83\u4ece\u629b\u51fa\u5f02\u5e38\u7684\u51fd\u6570\u5f00\u59cb\uff0c\u4e00\u76f4\u5411\u4e0a\u8ffd\u6eaf\u5230\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u70b9\u3002<\/p>\n<p><strong>\u83b7\u53d6\u5806\u6808\u8ddf\u8e2a<\/strong><\/p>\n<p>\u8981\u83b7\u53d6\u5f02\u5e38\u7684\u5806\u6808\u8ddf\u8e2a\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>printStackTrace()<\/code> \u65b9\u6cd5\uff1a<\/p>\n<pre>try {\n  \/\/ \u8fd9\u91cc\u4f1a\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\n} catch (Exception $e) {\n  echo $e-&gt;getTraceAsString();\n}<\/pre>\n<p><code>getTraceAsString()<\/code> \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u5806\u6808\u8ddf\u8e2a\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>#0 \/path\/to\/file.php(10): function()\n#1 \/path\/to\/anotherfile.php(20): function()\n#2 \/path\/to\/index.php(30): function()<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6f14\u793a\u5982\u4f55\u5728\u629b\u51fa\u5f02\u5e38\u65f6\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;?php\n\nfunction divideByZero()\n{\n  $result = 10 \/ 0;\n}\n\ntry {\n  divideByZero();\n} catch (Exception $e) {\n  echo $e-&gt;getMessage() . \"\\n\";\n  echo $e-&gt;getTraceAsString();\n}<\/pre>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>Division by zero\n#0 \/path\/to\/script.php(15): divideByZero()\n#1 \/path\/to\/index.php(20): testFunction()<\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\u663e\u793a\u4e86\u5f02\u5e38\u6d88\u606f\u53ca\u5176\u5806\u6808\u8ddf\u8e2a\u3002\u5806\u6808\u8ddf\u8e2a\u8868\u660e\u5f02\u5e38\u662f\u7531 <code>divideByZero()<\/code> \u51fd\u6570\u4e2d\u7b2c 15 \u884c\u7684\u9664\u4ee5\u96f6\u64cd\u4f5c\u5f15\u8d77\u7684\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8ephp,\u5806\u6808\u8ddf\u8e2a\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f \u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300a\u629b\u51fa\u5f02\u5e38\u65f6\uff0cPHP \u5982\u4f55\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\uff1f\u300b\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9\u6587\u7ae0\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01 PHP \u4e2d\u53ef\u4ee5\u901a\u8fc7 printStackTrace() \u65b9\u6cd5\u83b7\u53d6\u5f02\u5e38\u5806\u6808\u8ddf\u8e2a\uff0c\u8bb0\u5f55\u4e86\u4ece\u5f02\u5e38\u629b\u51fa\u70b9\u5230\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u70b9\u7684\u8c03\u7528\u94fe\u4fe1\u606f\uff0c\u5305\u62ec\u51fd\u6570\u540d\u79f0\u3001\u6587\u4ef6\u8def\u5f84\u548c\u884c\u53f7\u3002 PHP \u4e2d\u5f02\u5e38\u5806\u6808\u8ddf\u8e2a\u8bb0\u5f55\uff1a\u5165\u95e8\u6307\u5357 \u7b80\u4ecb \u5728 PHP \u4e2d\uff0c\u5f53\u629b\u51fa\u5f02\u5e38\u65f6\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u8bb0\u5f55\u4e00\u4e2a\u5806\u6808\u8ddf\u8e2a\u4fe1\u606f\u3002\u8be5\u4fe1\u606f\u6355\u83b7\u4e86\u5f02\u5e38\u53d1\u751f\u65f6\u7684\u8c03\u7528\u94fe\uff0c\u5bf9\u4e8e\u8c03\u8bd5\u548c\u7406\u89e3\u9519\u8bef\u5f02\u5e38\u975e\u5e38\u6709\u5e2e\u52a9\u3002 \u4ec0\u4e48\u662f\u5806\u6808\u8ddf\u8e2a\uff1f \u5806\u6808\u8ddf\u8e2a\u662f\u4e00\u7cfb\u5217\u5e27\uff08\u4e5f\u79f0\u4e3a\u5806\u6808\u5e27\uff09\uff0c\u6bcf\u4e2a\u5e27\u90fd\u5305\u542b\u6709\u5173\u8c03\u7528\u51fd\u6570\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u51fd\u6570\u540d\u79f0\u3001\u6587\u4ef6\u8def\u5f84\u548c\u884c\u53f7\u3002\u5b83\u4ece\u629b\u51fa\u5f02\u5e38\u7684\u51fd\u6570\u5f00\u59cb\uff0c\u4e00\u76f4\u5411\u4e0a\u8ffd\u6eaf\u5230\u5e94\u7528\u7a0b\u5e8f\u5165\u53e3\u70b9\u3002 \u83b7\u53d6\u5806\u6808\u8ddf\u8e2a \u8981\u83b7\u53d6\u5f02\u5e38\u7684\u5806\u6808\u8ddf\u8e2a\uff0c\u53ef\u4ee5\u4f7f\u7528 printStackTrace() \u65b9\u6cd5\uff1a try { \/\/ \u8fd9\u91cc\u4f1a\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38 } catch (Exception $e) { echo $e-&gt;getTraceAsString(); } getTraceAsString() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u5806\u6808\u8ddf\u8e2a\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a #0 \/path\/to\/file.php(10): function() #1 \/path\/to\/anotherfile.php(20): function() #2 \/path\/to\/index.php(30): function() \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u6f14\u793a\u5982\u4f55\u5728\u629b\u51fa\u5f02\u5e38\u65f6\u8bb0\u5f55\u5806\u6808\u8ddf\u8e2a\u7684\u793a\u4f8b\uff1a &lt;?php function divideByZero() { $result = 10 \/ 0; } [&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-48232","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48232","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=48232"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48232\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}