{"id":49176,"date":"2024-12-02T10:02:02","date_gmt":"2024-12-02T02:02:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49176\/"},"modified":"2024-12-02T10:02:02","modified_gmt":"2024-12-02T02:02:02","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%e4%b8%ad%e5%ae%9a%e4%b9%89%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\/49176\/","title":{"rendered":"PHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241114\/17315699836735a93fb013d.jpg\" class=\"aligncenter\" title=\"PHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u63d2\u56fe\" alt=\"PHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php \u5b50\u7c7b\u4f7f\u7528\u7236\u7c7b\u9b54\u672f\u65b9\u6cd5<\/strong><\/p>\n<p>\u7236\u7c7b\u4e2d\u5b9a\u4e49\u4e86\u9b54\u672f\u65b9\u6cd5\uff0c\u5b50\u7c7b\u5982\u4f55\u624d\u80fd\u5728\u5b50\u7c7b\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u9b54\u672f\u65b9\u6cd5\u5462\uff1f<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u7236\u7c7b p\uff0c\u5b83\u5b9a\u4e49\u4e86\u4ee5\u4e0b\u9b54\u672f\u65b9\u6cd5\uff1a<\/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>\u8981\u5728\u5b50\u7c7b\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u9b54\u672f\u65b9\u6cd5\uff0c\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u5b9a\u4e49\u4e00\u4e2a\u5b50\u7c7b c \u7ee7\u627f\u7236\u7c7b p\u3002<\/li>\n<li>\u5728\u5b50\u7c7b\u6784\u9020\u51fd\u6570\u4e2d\u8c03\u7528\u7236\u7c7b\u6784\u9020\u51fd\u6570\u3002<\/li>\n<li>\u5728\u5b50\u7c7b\u4e2d\u5bf9\u7236\u7c7b\u79c1\u6709\u6210\u5458\u8fdb\u884c\u8d4b\u503c\uff0c\u8fd9\u5c06\u89e6\u53d1 __set() \u9b54\u672f\u65b9\u6cd5\u3002<\/li>\n<\/ol>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u5b50\u7c7b c \u7ee7\u627f\u4e86\u7236\u7c7b p \u9b54\u672f\u65b9\u6cd5\uff1a<\/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>\u521b\u5efa\u8be5\u5b50\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\u5e76\u8c03\u7528 showname() \u65b9\u6cd5\uff1a<\/p>\n<pre>$c = new C;\n$c-&gt;showName();<\/pre>\n<p>\u7531\u4e8e\u5b50\u7c7b\u7ee7\u627f\u4e86\u7236\u7c7b\u5e76\u8c03\u7528\u4e86\u7236\u7c7b\u6784\u9020\u51fd\u6570\uff0c\u56e0\u6b64\u5b50\u7c7b\u4e5f\u4f1a\u521d\u59cb\u5316 $name \u4e3a &#8220;hello&#8221;\u3002\u968f\u540e\uff0c\u5b50\u7c7b\u5bf9 $name \u8fdb\u884c\u8d4b\u503c\uff0c\u8fd9\u5c06\u89e6\u53d1 __set() \u9b54\u672f\u65b9\u6cd5\uff0c\u6700\u7ec8\u8f93\u51fa &#8220;\u4f60\u597d&#8221;\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u5b50\u7c7b\u53ef\u4ee5\u6269\u5c55\u548c\u589e\u5f3a\u7236\u7c7b\u7684\u529f\u80fd\uff0c\u800c\u65e0\u9700\u91cd\u65b0\u5b9a\u4e49\u9b54\u672f\u65b9\u6cd5\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u90fd\u6253\u5f00\u8fd9\u7bc7\u300aPHP \u5b50\u7c7b\u5982\u4f55\u4f7f\u7528\u7236\u7c7b\u4e2d\u5b9a\u4e49\u7684\u9b54\u672f\u65b9\u6cd5\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\uff0c\u5b66\u4e0b\u53bb\u5427\uff01\u672c\u6587\u4e3b\u8981\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5927\u5bb6\u5bf9\u672c\u6587\u6709\u597d\u7684\u5efa\u8bae\u6216\u8005\u770b\u5230\u6709\u4e0d\u8db3\u4e4b\u5904\uff0c\u975e\u5e38\u6b22\u8fce\u5927\u5bb6\u79ef\u6781\u63d0\u51fa\uff01\u5728\u540e\u7eed\u6587\u7ae0\u6211\u4f1a\u7ee7\u7eed\u66f4\u65b0\u6587\u7ae0\u76f8\u5173\u7684\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u6709\u6240\u5e2e\u52a9\uff01 php \u5b50\u7c7b\u4f7f\u7528\u7236\u7c7b\u9b54\u672f\u65b9\u6cd5 \u7236\u7c7b\u4e2d\u5b9a\u4e49\u4e86\u9b54\u672f\u65b9\u6cd5\uff0c\u5b50\u7c7b\u5982\u4f55\u624d\u80fd\u5728\u5b50\u7c7b\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u9b54\u672f\u65b9\u6cd5\u5462\uff1f \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u7236\u7c7b p\uff0c\u5b83\u5b9a\u4e49\u4e86\u4ee5\u4e0b\u9b54\u672f\u65b9\u6cd5\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; } } \u8981\u5728\u5b50\u7c7b\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u9b54\u672f\u65b9\u6cd5\uff0c\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u5b9a\u4e49\u4e00\u4e2a\u5b50\u7c7b c \u7ee7\u627f\u7236\u7c7b p\u3002 \u5728\u5b50\u7c7b\u6784\u9020\u51fd\u6570\u4e2d\u8c03\u7528\u7236\u7c7b\u6784\u9020\u51fd\u6570\u3002 \u5728\u5b50\u7c7b\u4e2d\u5bf9\u7236\u7c7b\u79c1\u6709\u6210\u5458\u8fdb\u884c\u8d4b\u503c\uff0c\u8fd9\u5c06\u89e6\u53d1 __set() \u9b54\u672f\u65b9\u6cd5\u3002 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u5b50\u7c7b c \u7ee7\u627f\u4e86\u7236\u7c7b p \u9b54\u672f\u65b9\u6cd5\uff1a class [&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-49176","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49176","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=49176"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49176\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}