{"id":47992,"date":"2024-12-02T16:18:36","date_gmt":"2024-12-02T08:18:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47992\/"},"modified":"2024-12-02T16:18:36","modified_gmt":"2024-12-02T08:18:36","slug":"php-%e9%97%ad%e5%8c%85%e4%b8%8e%e5%87%bd%e6%95%b0%e8%b0%83%e7%94%a8%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47992\/","title":{"rendered":"php \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b<\/h1>\n<p>\u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\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\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p>\u95ed\u5305\u548c\u51fd\u6570\u8c03\u7528\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u53d8\u91cf\u8bbf\u95ee\u6743\u9650\u548c\u4f5c\u7528\u57df\uff0c\u524d\u8005\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u4f5c\u7528\u57df\u53d8\u91cf\u5e76\u5ef6\u7eed\u4f5c\u7528\u57df\uff0c\u800c\u540e\u8005\u5219\u4e0d\u80fd\uff0c\u4e14\u4f5c\u7528\u57df\u4ec5\u6301\u7eed\u5230\u51fd\u6570\u6267\u884c\u7ed3\u675f\u3002\u5177\u4f53\u6848\u4f8b\u8bf4\u660e\uff1a\u95ed\u5305\u53ef\u4ee5\u8bbf\u95ee\u548c\u4fee\u6539\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\uff0c\u800c\u51fd\u6570\u8c03\u7528\u5219\u4e0d\u5177\u5907\u6b64\u80fd\u529b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729947692671ce82ca3823.jpg\" class=\"aligncenter\" title=\"php \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b\u63d2\u56fe\" alt=\"php \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b<\/strong><\/p>\n<p>\u95ed\u5305\u548c\u51fd\u6570\u8c03\u7528\u662f PHP \u4e2d\u6267\u884c\u4ee3\u7801\u7684\u4e24\u79cd\u5e38\u89c1\u65b9\u5f0f\u3002\u867d\u7136\u5b83\u4eec\u6709\u4e00\u4e9b\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u4e5f\u6709\u91cd\u8981\u7684\u533a\u522b\u3002<\/p>\n<p><strong>\u95ed\u5305<\/strong><\/p>\n<p>\u95ed\u5305\u662f\u5728 \u51fd\u6570\u5185\u90e8 \u5b9a\u4e49\u7684\u51fd\u6570\u3002\u5b83\u53ef\u4ee5\u8bbf\u95ee\u5176\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u5373\u4f7f\u5916\u90e8\u51fd\u6570\u5df2\u7ecf\u6267\u884c\u5b8c\u6210\u3002\u8fd9\u4f7f\u5f97\u95ed\u5305\u975e\u5e38\u9002\u5408\u9700\u8981\u8bbf\u95ee\u5916\u90e8\u51fd\u6570\u72b6\u6001\u7684\u573a\u666f\u3002<\/p>\n<p><strong>\u51fd\u6570\u8c03\u7528<\/strong><\/p>\n<p>\u51fd\u6570\u8c03\u7528\u662f\u901a\u8fc7\u4f7f\u7528\u51fd\u6570\u540d\u79f0\u5e76\u4f20\u9012\u4efb\u4f55\u5fc5\u8981\u7684\u53c2\u6570\u6765\u6267\u884c\u51fd\u6570\u3002\u51fd\u6570\u4e00\u65e6\u6267\u884c\u5b8c\u6210\uff0c\u5176\u4f5c\u7528\u57df\u5185\u7684\u6240\u6709\u53d8\u91cf\u548c\u6570\u636e\u90fd\u5c06\u88ab\u9500\u6bc1\u3002<\/p>\n<p><strong>\u4e3b\u8981\u533a\u522b<\/strong><\/p>\n<ul>\n<li><strong>\u53d8\u91cf\u8bbf\u95ee\uff1a<\/strong>\u95ed\u5305\u53ef\u4ee5\u8bbf\u95ee\u5176\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\uff0c\u800c\u51fd\u6570\u8c03\u7528\u4e0d\u80fd\u3002<\/li>\n<li><strong>\u4f5c\u7528\u57df\uff1a<\/strong>\u95ed\u5305\u7684\u4f5c\u7528\u57df\u4e00\u76f4\u6301\u7eed\u5230\u5b83\u88ab\u9500\u6bc1\uff0c\u800c\u51fd\u6570\u8c03\u7528\u7684\u4f5c\u7528\u57df\u53ea\u6301\u7eed\u5230\u51fd\u6570\u6267\u884c\u5b8c\u6210\u3002<\/li>\n<li><strong>\u5185\u5b58\u6548\u7387\uff1a<\/strong>\u7531\u4e8e\u95ed\u5305\u4fdd\u7559\u4e86\u5bf9\u5916\u90e8\u4f5c\u7528\u57df\u7684\u5f15\u7528\uff0c\u56e0\u6b64\u5b83\u4eec\u6bd4\u51fd\u6570\u8c03\u7528\u4f7f\u7528\u66f4\u591a\u7684\u5185\u5b58\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4f8b\u5b50\uff1a<\/p>\n<pre>function outer() {\n  $count = 0;\n\n  $increment = function() use ($count) {\n    $count++;\n  };\n\n  return $increment;\n}\n\n$increment = outer();\n$increment();<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>outer()<\/code> \u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u95ed\u5305 <code>$increment<\/code>\u3002<code>$increment<\/code> \u95ed\u5305\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf <code>$count<\/code>\u3002\u8c03\u7528 <code>$increment<\/code> \u95ed\u5305\u4f1a\u589e\u52a0 <code>$count<\/code> \u7684\u503c\u3002<\/p>\n<p>\u53e6\u4e00\u65b9\u9762\uff0c\u5982\u679c\u6211\u4eec\u4f7f\u7528\u51fd\u6570\u8c03\u7528\u6765\u589e\u52a0 <code>$count<\/code>\uff0c\u5219\u4e0d\u4f1a\u6709\u76f8\u540c\u7684\u6548\u679c\uff1a<\/p>\n<pre>function outer() {\n  $count = 0;\n\n  $increment = function() {\n    $count++;\n  };\n\n  $increment();\n}<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u8c03\u7528 <code>$increment<\/code> \u51fd\u6570\u4e0d\u4f1a\u4fee\u6539 <code>$count<\/code> \u7684\u503c\uff0c\u56e0\u4e3a\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u7684 <code>$count<\/code> \u662f\u4e00\u4e2a\u672c\u5730\u53d8\u91cf\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u95ed\u5305\u548c\u51fd\u6570\u8c03\u7528\u5728 PHP \u4e2d\u90fd\u662f\u5f3a\u5927\u7684\u5de5\u5177\u3002\u4e86\u89e3\u5b83\u4eec\u4e4b\u95f4\u7684\u533a\u522b\u5bf9\u4e8e\u9009\u62e9\u6700\u9002\u5408\u7279\u5b9a\u573a\u666f\u7684\u65b9\u6cd5\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aphp \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b \u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u300aphp \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b\u300b\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01 \u95ed\u5305\u548c\u51fd\u6570\u8c03\u7528\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u53d8\u91cf\u8bbf\u95ee\u6743\u9650\u548c\u4f5c\u7528\u57df\uff0c\u524d\u8005\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u4f5c\u7528\u57df\u53d8\u91cf\u5e76\u5ef6\u7eed\u4f5c\u7528\u57df\uff0c\u800c\u540e\u8005\u5219\u4e0d\u80fd\uff0c\u4e14\u4f5c\u7528\u57df\u4ec5\u6301\u7eed\u5230\u51fd\u6570\u6267\u884c\u7ed3\u675f\u3002\u5177\u4f53\u6848\u4f8b\u8bf4\u660e\uff1a\u95ed\u5305\u53ef\u4ee5\u8bbf\u95ee\u548c\u4fee\u6539\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\uff0c\u800c\u51fd\u6570\u8c03\u7528\u5219\u4e0d\u5177\u5907\u6b64\u80fd\u529b\u3002 PHP \u95ed\u5305\u4e0e\u51fd\u6570\u8c03\u7528\u7684\u533a\u522b \u95ed\u5305\u548c\u51fd\u6570\u8c03\u7528\u662f PHP \u4e2d\u6267\u884c\u4ee3\u7801\u7684\u4e24\u79cd\u5e38\u89c1\u65b9\u5f0f\u3002\u867d\u7136\u5b83\u4eec\u6709\u4e00\u4e9b\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u4e5f\u6709\u91cd\u8981\u7684\u533a\u522b\u3002 \u95ed\u5305 \u95ed\u5305\u662f\u5728 \u51fd\u6570\u5185\u90e8 \u5b9a\u4e49\u7684\u51fd\u6570\u3002\u5b83\u53ef\u4ee5\u8bbf\u95ee\u5176\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u5373\u4f7f\u5916\u90e8\u51fd\u6570\u5df2\u7ecf\u6267\u884c\u5b8c\u6210\u3002\u8fd9\u4f7f\u5f97\u95ed\u5305\u975e\u5e38\u9002\u5408\u9700\u8981\u8bbf\u95ee\u5916\u90e8\u51fd\u6570\u72b6\u6001\u7684\u573a\u666f\u3002 \u51fd\u6570\u8c03\u7528 \u51fd\u6570\u8c03\u7528\u662f\u901a\u8fc7\u4f7f\u7528\u51fd\u6570\u540d\u79f0\u5e76\u4f20\u9012\u4efb\u4f55\u5fc5\u8981\u7684\u53c2\u6570\u6765\u6267\u884c\u51fd\u6570\u3002\u51fd\u6570\u4e00\u65e6\u6267\u884c\u5b8c\u6210\uff0c\u5176\u4f5c\u7528\u57df\u5185\u7684\u6240\u6709\u53d8\u91cf\u548c\u6570\u636e\u90fd\u5c06\u88ab\u9500\u6bc1\u3002 \u4e3b\u8981\u533a\u522b \u53d8\u91cf\u8bbf\u95ee\uff1a\u95ed\u5305\u53ef\u4ee5\u8bbf\u95ee\u5176\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\uff0c\u800c\u51fd\u6570\u8c03\u7528\u4e0d\u80fd\u3002 \u4f5c\u7528\u57df\uff1a\u95ed\u5305\u7684\u4f5c\u7528\u57df\u4e00\u76f4\u6301\u7eed\u5230\u5b83\u88ab\u9500\u6bc1\uff0c\u800c\u51fd\u6570\u8c03\u7528\u7684\u4f5c\u7528\u57df\u53ea\u6301\u7eed\u5230\u51fd\u6570\u6267\u884c\u5b8c\u6210\u3002 \u5185\u5b58\u6548\u7387\uff1a\u7531\u4e8e\u95ed\u5305\u4fdd\u7559\u4e86\u5bf9\u5916\u90e8\u4f5c\u7528\u57df\u7684\u5f15\u7528\uff0c\u56e0\u6b64\u5b83\u4eec\u6bd4\u51fd\u6570\u8c03\u7528\u4f7f\u7528\u66f4\u591a\u7684\u5185\u5b58\u3002 \u5b9e\u6218\u6848\u4f8b \u8003\u8651\u4ee5\u4e0b\u4f8b\u5b50\uff1a function outer() { $count = 0; $increment = function() use ($count) { $count++; }; return $increment; } $increment = outer(); $increment(); \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0couter() \u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u95ed\u5305 $increment\u3002$increment \u95ed\u5305\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u51fd\u6570\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf $count\u3002\u8c03\u7528 $increment \u95ed\u5305\u4f1a\u589e\u52a0 $count \u7684\u503c\u3002 \u53e6\u4e00\u65b9\u9762\uff0c\u5982\u679c\u6211\u4eec\u4f7f\u7528\u51fd\u6570\u8c03\u7528\u6765\u589e\u52a0 $count\uff0c\u5219\u4e0d\u4f1a\u6709\u76f8\u540c\u7684\u6548\u679c\uff1a function [&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-47992","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47992","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=47992"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47992\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}