{"id":47020,"date":"2024-12-02T10:28:09","date_gmt":"2024-12-02T02:28:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47020\/"},"modified":"2024-12-02T10:28:09","modified_gmt":"2024-12-02T02:28:09","slug":"php-%e5%87%bd%e6%95%b0%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%bc%95%e7%94%a8%e4%b8%8e%e5%bc%b1%e5%bc%95%e7%94%a8%e6%9c%89%e4%bd%95%e4%b8%8d%e5%90%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47020\/","title":{"rendered":"PHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u6709\u4f55\u4e0d\u540c"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u6709\u4f55\u4e0d\u540c<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u6709\u4f55\u4e0d\u540c\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729860204671b926cb952c.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u6709\u4f55\u4e0d\u540c\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u6709\u4f55\u4e0d\u540c\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u7684\u533a\u522b<\/strong><\/p>\n<p><strong>\u5f15\u7528<\/strong><\/p>\n<ul>\n<li>\u5f15\u7528\u521b\u5efa\u4e00\u4e2a\u53d8\u91cf\u7684\u522b\u540d\uff0c\u6307\u5411\u76f8\u540c\u5185\u5b58\u5730\u5740\u3002<\/li>\n<li>\u5bf9\u5f15\u7528\u8fdb\u884c\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4f1a\u5f71\u54cd\u539f\u59cb\u53d8\u91cf\u3002<\/li>\n<li>\u5f15\u7528\u4f7f\u7528 <code>&amp;<\/code> \u7b26\u53f7\u4f20\u9012\u3002<\/li>\n<\/ul>\n<p><strong>\u4f8b\u5982\uff1a<\/strong><\/p>\n<pre>$a = 10;\n$b =&amp; $a; \/\/ \u521b\u5efa\u5bf9 $a \u7684\u5f15\u7528\n\necho $a; \/\/ \u8f93\u51fa 10\n$b = 20; \/\/ \u66f4\u6539\u5f15\u7528\u4f1a\u5f71\u54cd\u539f\u59cb\u503c\necho $a; \/\/ \u8f93\u51fa 20\n?&gt;<\/pre>\n<p><strong>\u5f31\u5f15\u7528<\/strong><\/p>\n<ul>\n<li>\u5f31\u5f15\u7528\u662f\u4e00\u79cd\u8f6f\u5f15\u7528\u5f62\u5f0f\uff0c\u5f53\u5f15\u7528\u5bf9\u8c61\u4e0d\u518d\u88ab\u4f7f\u7528\u65f6\uff0cPHP \u5783\u573e\u6536\u96c6\u5668\u53ef\u4ee5\u81ea\u52a8\u5c06\u5176\u5220\u9664\u3002<\/li>\n<li>\u5bf9\u5f31\u5f15\u7528\u7684\u66f4\u6539\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u53d8\u91cf\u3002<\/li>\n<li>\u5f31\u5f15\u7528\u4f7f\u7528 <code>weak<\/code> \u5173\u952e\u5b57\u4f20\u9012\u3002<\/li>\n<\/ul>\n<p><strong>\u4f8b\u5982\uff1a<\/strong><\/p>\n<pre>$a = 10;\n$b = weak $a; \/\/ \u521b\u5efa\u5bf9 $a \u7684\u5f31\u5f15\u7528\n\necho $a; \/\/ \u8f93\u51fa 10\nunset($a); \/\/ \u9500\u6bc1\u539f\u59cb\u503c\necho $b; \/\/ \u8f93\u51fa NULL\uff0c\u56e0\u4e3a\u539f\u59cb\u503c\u5df2\u88ab\u9500\u6bc1\n?&gt;<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u51fd\u6570\u53c2\u6570\uff1a<\/strong><\/p>\n<pre>function increment(&amp;$n) {\n  $n++;\n}\n\n$num = 10;\nincrement($num);\necho $num; \/\/ \u8f93\u51fa 11<\/pre>\n<p><strong>\u901a\u8fc7\u5f31\u5f15\u7528\u7f13\u5b58\u7f13\u6162\u52a0\u8f7d\u7684\u6570\u636e\uff1a<\/strong><\/p>\n<pre>class SlowDataSource {\n  public function getData() {\n    \/\/ ... \u6a21\u62df\u7f13\u6162\u6570\u636e\u52a0\u8f7d\n  }\n}\n\n$data = NULL;\n$dataSource = new SlowDataSource();\n\nfunction getData(): SlowDataSource {\n  global $data, $dataSource;\n\n  if ($data === NULL) {\n    $data = weak $dataSource-&gt;getData();\n  }\n\n  return $data;\n}\n\n\/\/ \u521d\u6b21\u52a0\u8f7d\u6570\u636e\n$data1 = getData();\n\n\/\/ \u540e\u7eed\u83b7\u53d6\u6570\u636e\uff08\u5df2\u7f13\u5b58\uff09\n$data2 = getData();<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u6709\u4f55\u4e0d\u540c \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\u300aPHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u6709\u4f55\u4e0d\u540c\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01 PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4e0e\u5f31\u5f15\u7528\u7684\u533a\u522b \u5f15\u7528 \u5f15\u7528\u521b\u5efa\u4e00\u4e2a\u53d8\u91cf\u7684\u522b\u540d\uff0c\u6307\u5411\u76f8\u540c\u5185\u5b58\u5730\u5740\u3002 \u5bf9\u5f15\u7528\u8fdb\u884c\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4f1a\u5f71\u54cd\u539f\u59cb\u53d8\u91cf\u3002 \u5f15\u7528\u4f7f\u7528 &amp; \u7b26\u53f7\u4f20\u9012\u3002 \u4f8b\u5982\uff1a $a = 10; $b =&amp; $a; \/\/ \u521b\u5efa\u5bf9 $a \u7684\u5f15\u7528 echo $a; \/\/ \u8f93\u51fa 10 $b = 20; \/\/ \u66f4\u6539\u5f15\u7528\u4f1a\u5f71\u54cd\u539f\u59cb\u503c echo $a; \/\/ \u8f93\u51fa 20 ?&gt; \u5f31\u5f15\u7528 \u5f31\u5f15\u7528\u662f\u4e00\u79cd\u8f6f\u5f15\u7528\u5f62\u5f0f\uff0c\u5f53\u5f15\u7528\u5bf9\u8c61\u4e0d\u518d\u88ab\u4f7f\u7528\u65f6\uff0cPHP \u5783\u573e\u6536\u96c6\u5668\u53ef\u4ee5\u81ea\u52a8\u5c06\u5176\u5220\u9664\u3002 \u5bf9\u5f31\u5f15\u7528\u7684\u66f4\u6539\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u53d8\u91cf\u3002 \u5f31\u5f15\u7528\u4f7f\u7528 weak \u5173\u952e\u5b57\u4f20\u9012\u3002 \u4f8b\u5982\uff1a $a = 10; $b = weak $a; \/\/ [&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-47020","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47020","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=47020"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47020\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}