{"id":49066,"date":"2024-12-02T10:33:14","date_gmt":"2024-12-02T02:33:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49066\/"},"modified":"2024-12-02T10:33:14","modified_gmt":"2024-12-02T02:33:14","slug":"php%e5%ad%90%e7%b1%bb%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e7%88%b6%e7%b1%bb%e7%9a%84%e9%ad%94%e6%9c%af%e6%96%b9%e6%b3%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49066\/","title":{"rendered":"PHP\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241108\/1731051059672dbe33ba531.jpg\" class=\"aligncenter\" title=\"PHP\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u63d2\u56fe\" alt=\"PHP\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728php\u4e2d\uff0c\u5b50\u7c7b\u53ef\u4ee5\u7ee7\u627f\u7236\u7c7b\u7684\u6240\u6709\u65b9\u6cd5\uff0c\u5305\u62ec\u9b54\u672f\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u6848\u4f8b\uff1a<\/strong><br \/>\u7236\u7c7bp\u5b9a\u4e49\u4e86\u9b54\u672f\u65b9\u6cd5__set()\u6765\u8bbe\u7f6e\u79c1\u6709\u5c5e\u6027$name\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>class p {\n    private $name = \"\";\n\n    function __construct() {\n        $this-&gt;name = \"hello\";\n    }\n\n    public function __set($name, $value) {        \n        $this-&gt;$name = $value;      \n    }\n\n    public function showname() {\n        echo $this-&gt;name;\n    }\n}<\/pre>\n<p>\u5b50\u7c7bc\u7ee7\u627f\u4e86\u7236\u7c7bp\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>class C extends P {\n    function __construct() {\n        parent::__construct();\n\n        $this-&gt;name = \"\u4f60\u597d\";\n    }\n}<\/pre>\n<p>\u5728\u5b50\u7c7bc\u4e2d\u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\uff0c\u5148\u5f97\u5230$this-&gt;name = &#8216;hello&#8217;\u3002\u968f\u540e\u8fdb\u884c\u8d4b\u503c\uff0c\u4f1a\u76f4\u63a5\u8c03\u7528__set()\u65b9\u6cd5\uff0c\u5bf9name\u8fdb\u884c\u8d4b\u503c&#8217;\u4f60\u597d&#8217;\u3002<\/p>\n<p>\u56e0\u6b64\uff0c$this-&gt;showname()\u8f93\u51fa&#8217;\u4f60\u597d&#8217;\u3002<\/p>\n<p><strong>\u539f\u7406\uff1a<\/strong><br \/>\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u540e\uff0c\u5219\u5b50\u7c7b\u5c31\u53ef\u4ee5\u4f7f\u7528\u7236\u7c7b\u4e2d\u6240\u6709\u7684\u65b9\u6cd5\uff0c\u5305\u62ec\u9b54\u672f\u65b9\u6cd5\u3002\u5b50\u7c7b\u4e2d\u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\uff0c\u4f1a\u5148\u6267\u884c\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\uff0c\u7136\u540e\u6267\u884c\u5b50\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5\uff1f \u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01 php\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u7684\u9b54\u672f\u65b9\u6cd5 \u5728php\u4e2d\uff0c\u5b50\u7c7b\u53ef\u4ee5\u7ee7\u627f\u7236\u7c7b\u7684\u6240\u6709\u65b9\u6cd5\uff0c\u5305\u62ec\u9b54\u672f\u65b9\u6cd5\u3002 \u6848\u4f8b\uff1a\u7236\u7c7bp\u5b9a\u4e49\u4e86\u9b54\u672f\u65b9\u6cd5__set()\u6765\u8bbe\u7f6e\u79c1\u6709\u5c5e\u6027$name\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a class p { private $name = &#8220;&#8221;; function __construct() { $this-&gt;name = &#8220;hello&#8221;; } public function __set($name, $value) { $this-&gt;$name = $value; } public function showname() { echo $this-&gt;name; } } \u5b50\u7c7bc\u7ee7\u627f\u4e86\u7236\u7c7bp\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a class C extends P { function __construct() { parent::__construct(); $this-&gt;name = &#8220;\u4f60\u597d&#8221;; } } \u5728\u5b50\u7c7bc\u4e2d\u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\uff0c\u5148\u5f97\u5230$this-&gt;name = [&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-49066","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49066","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=49066"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49066\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}