{"id":48494,"date":"2024-12-02T15:02:12","date_gmt":"2024-12-02T07:02:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48494\/"},"modified":"2024-12-02T15:02:12","modified_gmt":"2024-12-02T07:02:12","slug":"%e5%8f%af%e5%8f%98%e5%8f%82%e6%95%b0%e5%9c%a8-php-%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95%e4%b8%ad%e7%9a%84%e4%bd%9c%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48494\/","title":{"rendered":"\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p>\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\uff0c\u53ef\u53d8\u53c2\u6570\u5141\u8bb8\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570\uff0c\u8bed\u6cd5\u4e3a\u51fd\u6570\u53c2\u6570\u5217\u8868\u672b\u5c3e\u7684\u4e09\u4e2a\u70b9\uff08&#8230;\uff09\u3002\u8fd9\u63d0\u4f9b\u4ee5\u4e0b\u4f18\u70b9\uff1a\u7075\u6d3b\u6027\uff1a\u652f\u6301\u6d4b\u8bd5\u51fd\u6570\u7684\u4e0d\u540c\u8f93\u5165\u7ec4\u5408\u3002\u53ef\u8bfb\u6027\uff1a\u63d0\u9ad8\u6d4b\u8bd5\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u65e0\u9700\u91cd\u590d\u53c2\u6570\u5217\u8868\u3002\u7b80\u6d01\u6027\uff1a\u51cf\u5c11\u6d4b\u8bd5\u4ee3\u7801\u6570\u91cf\uff0c\u7b80\u5316\u7ef4\u62a4\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730036977671e44f1c4353.jpg\" class=\"aligncenter\" title=\"\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528\u63d2\u56fe\" alt=\"\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528<\/strong><\/p>\n<p>\u5728\u7f16\u5199 PHP \u5355\u5143\u6d4b\u8bd5\u65f6\uff0c<strong>\u53ef\u53d8\u53c2\u6570<\/strong> \u5141\u8bb8\u60a8\u5411\u51fd\u6570\u4f20\u9012\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570\u3002\u8fd9\u5728\u6d4b\u8bd5\u9700\u8981\u591a\u79cd\u8f93\u5165\u6216\u5e0c\u671b\u7b80\u5316\u6d4b\u8bd5\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>\u8981\u5b9a\u4e49\u53ef\u53d8\u53c2\u6570\uff0c\u8bf7\u5728\u51fd\u6570\u7684\u53c2\u6570\u5217\u8868\u7684\u672b\u5c3e\u4f7f\u7528\u4e09\u4e2a\u70b9 <code>...<\/code>\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>function sum(...$numbers): int\n{\n    $total = 0;\n    foreach ($numbers as $number) {\n        $total += $number;\n    }\n    return $total;\n}<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6d4b\u8bd5\u5e26\u6709\u53ef\u53d8\u53c2\u6570\u51fd\u6570\u7684\u5b9e\u6218\u6848\u4f8b\uff1a<\/p>\n<p><strong><code>test\/SumTest.php<\/code><\/strong><\/p>\n<pre>use PHPUnit\\Framework\\TestCase;\n\nclass SumTest extends TestCase\n{\n    public function testSum(): void\n    {\n        $this-&gt;assertEquals(0, sum());\n        $this-&gt;assertEquals(10, sum(1, 2, 3, 4, 5));\n    }\n}<\/pre>\n<p>\u5728 <code>sum()<\/code> \u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f20\u9012\u4efb\u610f\u591a\u4e2a\u6570\u5b57\uff0c\u800c\u5355\u5143\u6d4b\u8bd5 <code>testSum()<\/code> \u9a8c\u8bc1\u4e86\u5b83\u662f\u5426\u6b63\u786e\u5730\u8ba1\u7b97\u4e86\u603b\u548c\u3002<\/p>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<p>\u4f7f\u7528\u53ef\u53d8\u53c2\u6570\u5728\u5355\u5143\u6d4b\u8bd5\u4e2d\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9\uff1a<\/p>\n<ul>\n<li><strong>\u7075\u6d3b\u6027\uff1a<\/strong> \u5141\u8bb8\u60a8\u6d4b\u8bd5\u51fd\u6570\u7684\u4e0d\u540c\u8f93\u5165\u7ec4\u5408\u3002<\/li>\n<li><strong>\u53ef\u8bfb\u6027\uff1a<\/strong> \u63d0\u9ad8\u6d4b\u8bd5\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u56e0\u4e3a\u5b83\u6d88\u9664\u4e86\u5bf9\u591a\u6b21\u53c2\u6570\u5217\u8868\u7684\u9700\u6c42\u3002<\/li>\n<li><strong>\u7b80\u6d01\u6027\uff1a<\/strong> \u901a\u8fc7\u51cf\u5c11\u6d4b\u8bd5\u4ee3\u7801\u7684\u6570\u91cf\uff0c\u7b80\u5316\u6d4b\u8bd5\u7ef4\u62a4\u3002<\/li>\n<\/ul>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u662f\u4e00\u4e2a\u6709\u7528\u7684\u5de5\u5177\uff0c\u5b83\u63d0\u4f9b\u4e86\u7075\u6d3b\u6027\u3001\u53ef\u8bfb\u6027\u548c\u7b80\u6d01\u6027\u3002\u901a\u8fc7\u5229\u7528\u53ef\u53d8\u53c2\u6570\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199\u66f4\u6709\u6548\u4e14\u6613\u4e8e\u7ef4\u62a4\u7684\u6d4b\u8bd5\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528 \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300a\u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ \u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\uff0c\u53ef\u53d8\u53c2\u6570\u5141\u8bb8\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570\uff0c\u8bed\u6cd5\u4e3a\u51fd\u6570\u53c2\u6570\u5217\u8868\u672b\u5c3e\u7684\u4e09\u4e2a\u70b9\uff08&#8230;\uff09\u3002\u8fd9\u63d0\u4f9b\u4ee5\u4e0b\u4f18\u70b9\uff1a\u7075\u6d3b\u6027\uff1a\u652f\u6301\u6d4b\u8bd5\u51fd\u6570\u7684\u4e0d\u540c\u8f93\u5165\u7ec4\u5408\u3002\u53ef\u8bfb\u6027\uff1a\u63d0\u9ad8\u6d4b\u8bd5\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u65e0\u9700\u91cd\u590d\u53c2\u6570\u5217\u8868\u3002\u7b80\u6d01\u6027\uff1a\u51cf\u5c11\u6d4b\u8bd5\u4ee3\u7801\u6570\u91cf\uff0c\u7b80\u5316\u7ef4\u62a4\u3002 \u53ef\u53d8\u53c2\u6570\u5728 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u4f5c\u7528 \u5728\u7f16\u5199 PHP \u5355\u5143\u6d4b\u8bd5\u65f6\uff0c\u53ef\u53d8\u53c2\u6570 \u5141\u8bb8\u60a8\u5411\u51fd\u6570\u4f20\u9012\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570\u3002\u8fd9\u5728\u6d4b\u8bd5\u9700\u8981\u591a\u79cd\u8f93\u5165\u6216\u5e0c\u671b\u7b80\u5316\u6d4b\u8bd5\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u7528\u3002 \u8bed\u6cd5 \u8981\u5b9a\u4e49\u53ef\u53d8\u53c2\u6570\uff0c\u8bf7\u5728\u51fd\u6570\u7684\u53c2\u6570\u5217\u8868\u7684\u672b\u5c3e\u4f7f\u7528\u4e09\u4e2a\u70b9 &#8230;\u3002\u4f8b\u5982\uff1a function sum(&#8230;$numbers): int { $total = 0; foreach ($numbers as $number) { $total += $number; } return $total; } \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u6d4b\u8bd5\u5e26\u6709\u53ef\u53d8\u53c2\u6570\u51fd\u6570\u7684\u5b9e\u6218\u6848\u4f8b\uff1a test\/SumTest.php use PHPUnit\\Framework\\TestCase; class SumTest extends TestCase { public function testSum(): void { $this-&gt;assertEquals(0, sum()); [&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-48494","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48494","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=48494"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48494\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}