{"id":47090,"date":"2024-12-02T14:37:22","date_gmt":"2024-12-02T06:37:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47090\/"},"modified":"2024-12-02T14:37:22","modified_gmt":"2024-12-02T06:37:22","slug":"php-%e5%87%bd%e6%95%b0%e4%b8%ad%e5%bc%95%e7%94%a8%e5%af%b9%e8%b1%a1%e6%97%b6%e4%bc%9a%e5%8f%91%e7%94%9f%e4%bb%80%e4%b9%88%e6%83%85%e5%86%b5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47090\/","title":{"rendered":"PHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aPHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f\u300b\uff0c\u8986\u76d6\u4e86\u6587\u7ae0\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u5f53\u5bf9\u8c61\u4ee5\u5f15\u7528\u4f20\u9012\u7ed9\u51fd\u6570\u65f6\uff0c\u5bf9\u8be5\u5bf9\u8c61\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4f1a\u53cd\u6620\u5728\u5176\u539f\u59cb\u503c\u4e0a\u3002\u8fd9\u8868\u660e\u51fd\u6570\u63a5\u6536\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u526f\u672c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729865495671ba7170196f.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u51fd\u6570\u53ef\u4ee5\u5f15\u7528\u5bf9\u8c61\uff0c\u8fd9\u4e0e\u5f15\u7528\u503c\u7c7b\u4f3c\u3002\u5f53\u5bf9\u8c61\u4ee5\u5f15\u7528\u65b9\u5f0f\u4f20\u9012\u65f6\uff0c\u5bf9\u8be5\u5bf9\u8c61\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u5c06\u53cd\u6620\u5728\u5176\u539f\u59cb\u503c\u4e0a\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>function myFunction(&amp;$object) {\n    \/\/ ...\n}<\/pre>\n<p>\u5176\u4e2d\uff0c<code>&amp;<\/code> \u7b26\u53f7\u8868\u793a\u5bf9\u8be5\u5bf9\u8c61\u4f7f\u7528\u5f15\u7528\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>class Person {\n    public $name;\n    public $age;\n}\n\n\/\/ \u521b\u5efa\u4e00\u4e2a Person \u5bf9\u8c61\n$person = new Person();\n$person-&gt;name = 'John';\n$person-&gt;age = 30;\n\n\/\/ \u4f7f\u7528\u5f15\u7528\u5c06\u5bf9\u8c61\u4f20\u9012\u7ed9\u51fd\u6570\nfunction changeName(&amp;$person) {\n    $person-&gt;name = 'Mary';\n}\n\n\/\/ \u8c03\u7528\u51fd\u6570\nchangeName($person);\n\n\/\/ \u6253\u5370\u5bf9\u8c61\u7684\u72b6\u6001\necho $person-&gt;name; \/\/ \u8f93\u51fa\uff1aMary<\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>changeName()<\/code> \u51fd\u6570\u4f7f\u7528\u5f15\u7528\u63a5\u6536 <code>$person<\/code> \u5bf9\u8c61\u3002\u5f53\u8be5\u51fd\u6570\u4fee\u6539 <code>$person-&gt;name<\/code> \u65f6\uff0c\u5b83\u4e5f\u4f1a\u4fee\u6539\u539f\u59cb\u5bf9\u8c61\u7684\u540d\u79f0\u3002\u56e0\u6b64\uff0c\u5f53\u6211\u4eec\u6253\u5370 <code>$person-&gt;name<\/code> \u65f6\uff0c\u5b83\u4f1a\u663e\u793a <code>Mary<\/code>\u3002<\/p>\n<p><strong>\u9650\u5236\uff1a<\/strong><\/p>\n<p>\u5f53\u5f15\u7528\u5bf9\u8c61\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u9650\u5236\uff1a<\/p>\n<ul>\n<li><strong>\u5b89\u5168\u6027\uff1a<\/strong>\u5bf9\u5f15\u7528\u5bf9\u8c61\u7684\u66f4\u6539\u5c06\u5f71\u54cd\u6240\u6709\u5f15\u7528\u5b83\u7684\u53d8\u91cf\uff0c\u53ef\u80fd\u5bfc\u81f4\u610f\u5916\u884c\u4e3a\u3002<\/li>\n<li><strong>\u6027\u80fd\uff1a<\/strong>\u5bf9\u5f15\u7528\u5bf9\u8c61\u7684\u9891\u7e41\u4fee\u6539\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\uff0c\u56e0\u4e3a\u6bcf\u6b21\u66f4\u6539\u90fd\u4f1a\u5f71\u54cd\u6240\u6709\u5f15\u7528\u3002<\/li>\n<\/ul>\n<p><strong>\u6700\u4f73\u5b9e\u8df5\uff1a<\/strong><\/p>\n<ul>\n<li>\u53ea\u6709\u5728\u9700\u8981\u5bf9\u5bf9\u8c61\u8fdb\u884c\u4fee\u6539\u65f6\u624d\u4f7f\u7528\u5f15\u7528\u3002<\/li>\n<li>\u5f53\u4e0d\u518d\u9700\u8981\u5f15\u7528\u65f6\uff0c\u4f7f\u7528 <code>unset()<\/code> \u51fd\u6570\u6e05\u9664\u5f15\u7528\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528\u4e0d\u53ef\u53d8\u5bf9\u8c61\uff0c\u4ee5\u907f\u514d\u610f\u5916\u66f4\u6539\u3002<\/li>\n<\/ul>\n<p>\u6587\u4e2d\u5173\u4e8ephp,\u5bf9\u8c61\u5f15\u7528\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f \u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aPHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\uff1f\u300b\uff0c\u8986\u76d6\u4e86\u6587\u7ae0\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002 \u5728 PHP \u4e2d\uff0c\u5f53\u5bf9\u8c61\u4ee5\u5f15\u7528\u4f20\u9012\u7ed9\u51fd\u6570\u65f6\uff0c\u5bf9\u8be5\u5bf9\u8c61\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4f1a\u53cd\u6620\u5728\u5176\u539f\u59cb\u503c\u4e0a\u3002\u8fd9\u8868\u660e\u51fd\u6570\u63a5\u6536\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u526f\u672c\u3002 PHP \u51fd\u6570\u4e2d\u5f15\u7528\u5bf9\u8c61\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5 \u5728 PHP \u4e2d\uff0c\u51fd\u6570\u53ef\u4ee5\u5f15\u7528\u5bf9\u8c61\uff0c\u8fd9\u4e0e\u5f15\u7528\u503c\u7c7b\u4f3c\u3002\u5f53\u5bf9\u8c61\u4ee5\u5f15\u7528\u65b9\u5f0f\u4f20\u9012\u65f6\uff0c\u5bf9\u8be5\u5bf9\u8c61\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u5c06\u53cd\u6620\u5728\u5176\u539f\u59cb\u503c\u4e0a\u3002 \u8bed\u6cd5\uff1a function myFunction(&amp;$object) { \/\/ &#8230; } \u5176\u4e2d\uff0c&amp; \u7b26\u53f7\u8868\u793a\u5bf9\u8be5\u5bf9\u8c61\u4f7f\u7528\u5f15\u7528\u3002 \u5b9e\u6218\u6848\u4f8b\uff1a \u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\uff1a class Person { public $name; public $age; } \/\/ \u521b\u5efa\u4e00\u4e2a Person \u5bf9\u8c61 $person = new Person(); $person-&gt;name = &#8216;John&#8217;; $person-&gt;age = 30; \/\/ \u4f7f\u7528\u5f15\u7528\u5c06\u5bf9\u8c61\u4f20\u9012\u7ed9\u51fd\u6570 function changeName(&amp;$person) { $person-&gt;name = &#8216;Mary&#8217;; } [&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-47090","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47090","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=47090"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47090\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}