{"id":49300,"date":"2024-12-02T17:52:32","date_gmt":"2024-12-02T09:52:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49300\/"},"modified":"2024-12-02T17:52:32","modified_gmt":"2024-12-02T09:52:32","slug":"%e6%8e%8c%e6%8f%a1-php-%e4%b8%ad%e7%9a%84%e7%ae%80%e6%b4%81%e4%bb%a3%e7%a0%81%ef%bc%9a%e6%88%91%e7%9a%84%e7%bc%96%e7%a0%81%e4%b9%8b%e6%97%85%e7%9a%84%e4%b8%bb%e8%a6%81%e7%bb%8f%e9%aa%8c%e6%95%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49300\/","title":{"rendered":"\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17326888576746bbd976722.jpg\" class=\"aligncenter\" title=\"\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad\u63d2\u56fe\" alt=\"\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad\u63d2\u56fe\" \/><\/p>\n<p>\u300a\u638c\u63e1 php \u4e2d\u7684\u5e72\u51c0\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u4e2d\u7684\u91cd\u8981\u6559\u8bad\u300b\u91cd\u70b9\u4ecb\u7ecd\u5b9e\u7528\u7684\u5b9e\u8df5\u89c4\u5219\u548c\u793a\u4f8b\uff0c\u4ee5\u5e2e\u52a9 php \u5f00\u53d1\u4eba\u5458\u7f16\u5199\u5e72\u51c0\u3001\u53ef\u7ef4\u62a4\u4e14\u9ad8\u6548\u7684\u4ee3\u7801\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u628a\u8fd9\u4e9b\u57fa\u672c\u89c4\u5219\u5206\u89e3\u4e3a\u6613\u4e8e\u7406\u89e3\u7684\u90e8\u5206\uff0c\u6bcf\u4e2a\u90e8\u5206\u90fd\u9644\u6709\u4e00\u4e2a\u793a\u4f8b\u3002<\/p>\n<h3> 1. <strong>\u6709\u610f\u4e49\u7684\u540d\u5b57<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u4e3a\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u4f7f\u7528\u6e05\u6670\u4e14\u63cf\u8ff0\u6027\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u8fd9\u4f7f\u60a8\u7684\u4ee3\u7801\u66f4\u6613\u4e8e\u7406\u89e3\u548c\u7ef4\u62a4\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>   \/\/ bad:\n   $x = 25;\n   function d($a, $b) {\n       return $a + $b;\n   }\n\n   \/\/ good:\n   $age = 25;\n   function calculatesum($firstnumber, $secondnumber) {\n       return $firstnumber + $secondnumber;\n   }\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li>\u907f\u514d\u4f7f\u7528\u5355\u5b57\u6bcd\u53d8\u91cf\uff0c\u4f8b\u5982 $x \u6216 $d\u3002\u76f8\u53cd\uff0c\u8bf7\u4f7f\u7528\u63cf\u8ff0\u6027\u540d\u79f0\uff0c\u4f8b\u5982 $age \u6216calculatesum\u3002<\/li>\n<li>\u6e05\u6670\u7684\u540d\u79f0\u4f7f\u60a8\u7684\u610f\u56fe\u660e\u786e\uff0c\u5e2e\u52a9\u5f53\u524d\u548c\u672a\u6765\u7684\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u4ee3\u7801\u7684\u7528\u9014\u3002<\/li>\n<\/ul>\n<h3> 2. <strong>\u5355\u4e00\u8d23\u4efb\u539f\u5219\uff08srp\uff09<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u4e00\u4e2a\u51fd\u6570\u6216\u7c7b\u5e94\u8be5\u53ea\u6709\u4e00\u4e2a\u6539\u53d8\u7684\u7406\u7531\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u5e94\u8be5\u53ea\u505a\u4e00\u4ef6\u4e8b\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u8fd9\u4f7f\u60a8\u7684\u4ee3\u7801\u66f4\u52a0\u6a21\u5757\u5316\u5e76\u4e14\u66f4\u5bb9\u6613\u91cd\u6784\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>   \/\/ bad:\n   class order {\n       public function calculatetotal() {\n           \/\/ logic to calculate total\n       }\n\n       public function sendinvoiceemail() {\n           \/\/ logic to send email\n       }\n   }\n\n   \/\/ good:\n   class order {\n       public function calculatetotal() {\n           \/\/ logic to calculate total\n       }\n   }\n\n   class invoicemailer {\n       public function sendinvoiceemail() {\n           \/\/ logic to send email\n       }\n   }\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728 <strong>bad<\/strong> \u793a\u4f8b\u4e2d\uff0corder \u7c7b\u8d1f\u8d23\u8ba1\u7b97\u603b\u6570\u5e76\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u8fd9\u8fdd\u53cd\u4e86 srp\uff0c\u56e0\u4e3a\u5b83\u6709\u4e24\u4e2a\u8d23\u4efb\u3002<\/li>\n<li>\u5728<strong>good<\/strong>\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u521b\u5efa\u8d1f\u8d23\u7535\u5b50\u90ae\u4ef6\u4efb\u52a1\u7684 invoicemailer \u7c7b\u6765\u5206\u79bb\u5173\u6ce8\u70b9\uff0c\u4f7f\u6bcf\u4e2a\u7c7b\u66f4\u6613\u4e8e\u7ba1\u7406\u548c\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<h3> 3. <strong>\u4fdd\u6301\u51fd\u6570\u8f83\u5c0f<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u51fd\u6570\u5e94\u8be5\u505a\u4e00\u4ef6\u4e8b\u5e76\u4e14\u505a\u597d\u5b83\u3002\u5c06\u5927\u51fd\u6570\u5206\u89e3\u4e3a\u66f4\u5c0f\u7684\u51fd\u6570\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u5c0f\u51fd\u6570\u66f4\u5bb9\u6613\u7406\u89e3\u3001\u6d4b\u8bd5\u548c\u7ef4\u62a4\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>   \/\/ bad:\n   function processorder($order) {\n       \/\/ validate order\n       if (!$this-&gt;validateorder($order)) {\n           return false;\n       }\n\n       \/\/ calculate total\n       $total = $this-&gt;calculatetotal($order);\n\n       \/\/ send invoice\n       $this-&gt;sendinvoiceemail($order);\n\n       return true;\n   }\n\n   \/\/ good:\n   function processorder($order) {\n       if (!$this-&gt;isordervalid($order)) {\n           return false;\n       }\n\n       $this-&gt;finalizeorder($order);\n       return true;\n   }\n\n   private function isordervalid($order) {\n       return $this-&gt;validateorder($order);\n   }\n\n   private function finalizeorder($order) {\n       $total = $this-&gt;calculatetotal($order);\n       $this-&gt;sendinvoiceemail($order);\n   }\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728 <strong>bad<\/strong> \u793a\u4f8b\u4e2d\uff0cprocessorder \u51fd\u6570\u5c1d\u8bd5\u6267\u884c\u6240\u6709\u64cd\u4f5c\uff1a\u9a8c\u8bc1\u3001\u8ba1\u7b97\u548c\u53d1\u9001\u53d1\u7968\u3002<\/li>\n<li>\u5728 <strong>good<\/strong> \u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u4efb\u52a1\u5206\u89e3\u4e3a\u66f4\u5c0f\u3001\u66f4\u96c6\u4e2d\u7684\u65b9\u6cd5\uff08isordervalid\u3001finalizeorder\uff09\uff0c\u4ece\u800c\u63d0\u9ad8\u4e86\u53ef\u8bfb\u6027\u548c\u53ef\u91cd\u7528\u6027\u3002<\/li>\n<\/ul>\n<h3> 4. <strong>\u907f\u514d\u4f7f\u7528\u5e7b\u6570\u548c\u5b57\u7b26\u4e32<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u7528\u547d\u540d\u5e38\u91cf\u66ff\u6362\u201c\u795e\u5947\u201d\u6570\u5b57\u548c\u5b57\u7b26\u4e32\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u8fd9\u63d0\u9ad8\u4e86\u53ef\u8bfb\u6027\u5e76\u4f7f\u4ee3\u7801\u66f4\u5bb9\u6613\u4fee\u6539\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>   \/\/ bad:\n   if ($user-&gt;age &gt; 18) {\n       echo \"eligible\";\n   }\n\n   \/\/ good:\n   define('minimum_age', 18);\n\n   if ($user-&gt;age &gt; minimum_age) {\n       echo \"eligible\";\n   }\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728 <strong>bad<\/strong> \u793a\u4f8b\u4e2d\uff0c\u6570\u5b57 18 \u662f\u4e00\u4e2a\u201c\u795e\u5947\u6570\u5b57\u201d\u3002\u5728\u5206\u6790\u4e0a\u4e0b\u6587\u4e4b\u524d\uff0c\u4f60\u4e0d\u77e5\u9053\u5b83\u4ee3\u8868\u4ec0\u4e48\u3002<\/li>\n<li>\u5728 <strong>good<\/strong> \u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528 minimum_age \u4f7f\u610f\u56fe\u53d8\u5f97\u6e05\u6670\uff0c\u5e76\u5141\u8bb8\u60a8\u5728\u4e00\u4e2a\u4f4d\u7f6e\u66f4\u6539\u503c\u800c\u65e0\u9700\u641c\u7d22\u4ee3\u7801\u5e93\u3002<\/li>\n<\/ul>\n<h3> 5. <strong>dry\uff08\u4e0d\u8981\u91cd\u590d\u81ea\u5df1\uff09<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u907f\u514d\u91cd\u590d\u4ee3\u7801\u3002\u5c3d\u53ef\u80fd\u91cd\u7528\u51fd\u6570\u6216\u7c7b\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u91cd\u590d\u7684\u4ee3\u7801\u66f4\u96be\u7ef4\u62a4\u5e76\u4e14\u66f4\u5bb9\u6613\u51fa\u73b0\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>   \/\/ bad:\n   $total = $itemprice * $quantity;\n   $finalprice = $total - ($total * $discountrate);\n\n   $carttotal = $cartitemprice * $cartquantity;\n   $finalcartprice = $carttotal - ($carttotal * $cartdiscountrate);\n\n   \/\/ good:\n   function calculatefinalprice($price, $quantity, $discountrate) {\n       $total = $price * $quantity;\n       return $total - ($total * $discountrate);\n   }\n\n   $finalprice = calculatefinalprice($itemprice, $quantity, $discountrate);\n   $finalcartprice = calculatefinalprice($cartitemprice, $cartquantity, $cartdiscountrate);\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728<strong>bad<\/strong>\u793a\u4f8b\u4e2d\uff0c\u4ef7\u683c\u8ba1\u7b97\u903b\u8f91\u662f\u91cd\u590d\u7684\u3002<\/li>\n<li>\u5728<strong>good<\/strong>\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u53ef\u91cd\u7528\u7684\u51fd\u6570calculatefinalprice\u4ee5\u907f\u514d\u91cd\u590d\u5e76\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u7ef4\u62a4\u3002<\/li>\n<\/ul>\n<h3> 6. <strong>\u4f7f\u7528\u4fdd\u62a4\u5b50\u53e5\u6765\u51cf\u5c11\u5d4c\u5957<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u4e0d\u4f7f\u7528\u6df1\u5c42\u5d4c\u5957\u7684if\u8bed\u53e5\uff0c\u800c\u662f\u63d0\u524d\u8fd4\u56de\u4ee5\u7b80\u5316\u7ed3\u6784\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u4fdd\u62a4\u5b50\u53e5\u6d88\u9664\u4e86\u4e0d\u5fc5\u8981\u7684\u5d4c\u5957\uff0c\u4f7f\u4ee3\u7801\u66f4\u5e72\u51c0\u3001\u66f4\u6613\u4e8e\u9075\u5faa\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>   \/\/ bad:\n   function processpayment($amount) {\n       if ($amount &gt; 0) {\n           if ($this-&gt;ispaymentmethodavailable()) {\n               if ($this-&gt;isuserloggedin()) {\n                   \/\/ process payment\n               }\n           }\n       }\n   }\n\n   \/\/ good:\n   function processpayment($amount) {\n       if ($amount &lt;= 0) {\n           return;\n       }\n       if (!$this-&gt;ispaymentmethodavailable()) {\n           return;\n       }\n       if (!$this-&gt;isuserloggedin()) {\n           return;\n       }\n\n       \/\/ process payment\n   }\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728<strong>bad<\/strong>\u793a\u4f8b\u4e2d\uff0c\u903b\u8f91\u5d4c\u5957\u5f88\u6df1\uff0c\u5bfc\u81f4\u9605\u8bfb\u8d77\u6765\u66f4\u52a0\u56f0\u96be\u3002<\/li>\n<li>\u5728<strong>good<\/strong>\u793a\u4f8b\u4e2d\uff0c\u4fdd\u62a4\u5b50\u53e5\u7528\u4e8e\u5728\u4e0d\u6ee1\u8db3\u6761\u4ef6\u65f6\u63d0\u524d\u8fd4\u56de\uff0c\u4ece\u800c\u6241\u5e73\u5316\u7ed3\u6784\u5e76\u4f7f\u4ee3\u7801\u66f4\u6e05\u6670\u3002<\/li>\n<\/ul>\n<h3> 7. <strong>\u8bc4\u8bba\u201c\u4e3a\u4ec0\u4e48\u201d\uff0c\u800c\u4e0d\u662f\u201c\u4ec0\u4e48\u201d<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u7f16\u5199\u6ce8\u91ca\u6765\u89e3\u91ca\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f\u67d0\u4e9b\u4e8b\u60c5\uff0c\u800c\u4e0d\u662f\u89e3\u91ca\u6b63\u5728\u53d1\u751f\u7684\u4e8b\u60c5\uff08\u8fd9\u5e94\u8be5\u4ece\u4ee3\u7801\u4e2d\u6e05\u695a\u5730\u770b\u51fa\uff09\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u6ce8\u91ca\u5e94\u8be5\u63d0\u4f9b\u8d85\u8d8a\u663e\u800c\u6613\u89c1\u7684\u4ef7\u503c\uff0c\u6709\u52a9\u4e8e\u89e3\u91ca\u4ee3\u7801\u80cc\u540e\u7684\u610f\u56fe\u548c\u63a8\u7406\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>   \/\/ bad:\n   \/\/ increment age by 1\n   $age++;\n\n   \/\/ good:\n   \/\/ user's birthday has passed, increase age by 1\n   $age++;\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>bad<\/strong> \u6ce8\u91ca\u53ea\u662f\u91cd\u7533\u4e86\u4ee3\u7801\u7684\u4f5c\u7528\uff0c\u8fd9\u4ece\u4ee3\u7801\u672c\u8eab\u5c31\u5f88\u660e\u663e\u3002<\/li>\n<li><strong>good<\/strong>\u8bc4\u8bba\u89e3\u91ca\u4e86<strong>\u4e3a\u4ec0\u4e48<\/strong>\u6211\u4eec\u8981\u589e\u52a0\u5e74\u9f84\uff0c\u6dfb\u52a0\u6709\u610f\u4e49\u7684\u80cc\u666f\u3002<\/li>\n<\/ul>\n<h3> 8. <strong>\u4e3a\u4e86\u6e05\u6670\u800c\u91cd\u6784<\/strong> <\/h3>\n<ul>\n<li> <strong>\u89c4\u5219<\/strong>\uff1a\u4e0d\u65ad\u91cd\u6784\u4ee5\u63d0\u9ad8\u4ee3\u7801\u6e05\u6670\u5ea6\u548c\u7b80\u5355\u6027\u3002<\/li>\n<li> <strong>\u4e3a\u4ec0\u4e48<\/strong>\uff1a\u5e72\u51c0\u7684\u4ee3\u7801\u662f\u901a\u8fc7\u4e0d\u65ad\u91cd\u6784\u6765\u5b9e\u73b0\u7684\uff0c\u4ee5\u786e\u4fdd\u5b83\u59cb\u7ec8\u53ef\u8bfb\u3001\u9ad8\u6548\u548c\u53ef\u7ef4\u62a4\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre>   \/\/ Before Refactoring:\n   function getDiscountedPrice($price, $isHoliday) {\n       if ($isHoliday) {\n           return $price * 0.9;\n       } else {\n           return $price;\n       }\n   }\n\n   \/\/ After Refactoring:\n   function getDiscountedPrice($price, $isHoliday) {\n       return $isHoliday ? $price * 0.9 : $price;\n   }\n<\/pre>\n<p><strong>\u63cf\u8ff0<\/strong>\uff1a<\/p>\n<ul>\n<li>\u91cd\u6784\u5c06\u5197\u957f\u7684\u4ee3\u7801\u8f6c\u6362\u4e3a\u66f4\u7b80\u6d01\u3001\u4f18\u96c5\u7684\u7248\u672c\uff0c\u540c\u65f6\u53c8\u4e0d\u5931\u6e05\u6670\u5ea6\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e09\u5143\u8fd0\u7b97\u7b26\u7b80\u5316\u4e86 if-else \u7ed3\u6784\u3002<\/li>\n<\/ul>\n<hr>\n<p>\u8fd9\u4e9b\u57fa\u672c\u89c4\u5219\u6e90\u81ea\u5728 php \u4e2d\u5e72\u51c0\u7f16\u7801\u7684\u65c5\u7a0b\uff0c\u4f7f\u60a8\u7684\u4ee3\u7801\u66f4\u5177\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u901a\u8fc7\u4e00\u81f4\u5730\u5e94\u7528\u8fd9\u4e9b\u539f\u5219\uff0c\u60a8\u53ef\u4ee5\u786e\u4fdd\u60a8\u7684\u4ee3\u7801\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\u6613\u4e8e\u7406\u89e3\u548c\u4fee\u6539\uff0c\u65e0\u8bba\u60a8\u7684\u9879\u76ee\u6709\u591a\u590d\u6742\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad \u6536\u85cf \u5b66\u4e60\u6587\u7ae0\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u300a\u638c\u63e1 PHP \u4e2d\u7684\u7b80\u6d01\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u7684\u4e3b\u8981\u7ecf\u9a8c\u6559\u8bad\u300b\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\u6587\u7ae0\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01 \u300a\u638c\u63e1 php \u4e2d\u7684\u5e72\u51c0\u4ee3\u7801\uff1a\u6211\u7684\u7f16\u7801\u4e4b\u65c5\u4e2d\u7684\u91cd\u8981\u6559\u8bad\u300b\u91cd\u70b9\u4ecb\u7ecd\u5b9e\u7528\u7684\u5b9e\u8df5\u89c4\u5219\u548c\u793a\u4f8b\uff0c\u4ee5\u5e2e\u52a9 php \u5f00\u53d1\u4eba\u5458\u7f16\u5199\u5e72\u51c0\u3001\u53ef\u7ef4\u62a4\u4e14\u9ad8\u6548\u7684\u4ee3\u7801\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u628a\u8fd9\u4e9b\u57fa\u672c\u89c4\u5219\u5206\u89e3\u4e3a\u6613\u4e8e\u7406\u89e3\u7684\u90e8\u5206\uff0c\u6bcf\u4e2a\u90e8\u5206\u90fd\u9644\u6709\u4e00\u4e2a\u793a\u4f8b\u3002 1. \u6709\u610f\u4e49\u7684\u540d\u5b57 \u89c4\u5219\uff1a\u4e3a\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u4f7f\u7528\u6e05\u6670\u4e14\u63cf\u8ff0\u6027\u7684\u540d\u79f0\u3002 \u4e3a\u4ec0\u4e48\uff1a\u8fd9\u4f7f\u60a8\u7684\u4ee3\u7801\u66f4\u6613\u4e8e\u7406\u89e3\u548c\u7ef4\u62a4\u3002 \u793a\u4f8b\uff1a \/\/ bad: $x = 25; function d($a, $b) { return $a + $b; } \/\/ good: $age = 25; function calculatesum($firstnumber, $secondnumber) { return $firstnumber + $secondnumber; } \u63cf\u8ff0\uff1a \u907f\u514d\u4f7f\u7528\u5355\u5b57\u6bcd\u53d8\u91cf\uff0c\u4f8b\u5982 $x \u6216 $d\u3002\u76f8\u53cd\uff0c\u8bf7\u4f7f\u7528\u63cf\u8ff0\u6027\u540d\u79f0\uff0c\u4f8b\u5982 $age \u6216calculatesum\u3002 \u6e05\u6670\u7684\u540d\u79f0\u4f7f\u60a8\u7684\u610f\u56fe\u660e\u786e\uff0c\u5e2e\u52a9\u5f53\u524d\u548c\u672a\u6765\u7684\u5f00\u53d1\u4eba\u5458\u7406\u89e3\u4ee3\u7801\u7684\u7528\u9014\u3002 2. \u5355\u4e00\u8d23\u4efb\u539f\u5219\uff08srp\uff09 [&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-49300","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49300","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=49300"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49300\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}