{"id":1293,"date":"2025-11-04T16:03:49","date_gmt":"2025-11-04T08:03:49","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/1293.html"},"modified":"2025-11-04T16:03:50","modified_gmt":"2025-11-04T08:03:50","slug":"php%e7%b1%bb%e5%b1%9e%e6%80%a7%e6%8c%81%e4%b9%85%e5%8c%96%e4%b8%8e%e4%bf%ae%e6%94%b9%e6%96%b9%e6%b3%95","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/1293.html","title":{"rendered":"PHP\u7c7b\u5c5e\u6027\u6301\u4e45\u5316\u4e0e\u4fee\u6539\u65b9\u6cd5"},"content":{"rendered":"<p>\u5728PHP\u7c7b\u4e2d\uff0c\u5b8c\u5168\u53ef\u4ee5\u5b9e\u73b0\u60a8\u63cf\u8ff0\u7684\u529f\u80fd\u3002\u7c7b\u5c5e\u6027\uff08\u53d8\u91cf\uff09\u7684\u503c\u5728\u51fd\u6570\u8c03\u7528\u540e\u4f1a\u88ab\u6301\u4e45\u5316\u4fdd\u5b58\uff0c\u53ea\u8981\u60a8\u64cd\u4f5c\u7684\u662f<strong>\u540c\u4e00\u4e2a\u7c7b\u5b9e\u4f8b<\/strong>\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u539f\u7406\u548c\u793a\u4f8b\uff1a<\/p><h3 class=\"wp-block-heading\">\u5b9e\u73b0\u539f\u7406\uff1a<\/h3><ol class=\"wp-block-list\">\n<li><strong>\u7c7b\u5c5e\u6027\u6301\u4e45\u5316<\/strong>\uff1a\u7c7b\u4e2d\u7684\u5c5e\u6027\uff08\u5982<code>$A<\/code>\uff09\u5c5e\u4e8e\u5bf9\u8c61\u7684\u72b6\u6001\uff0c\u5176\u751f\u547d\u5468\u671f\u4e0e\u5bf9\u8c61\u5b9e\u4f8b\u76f8\u540c<\/li>\n\n\n\n<li><strong>\u4fee\u6539\u5c5e\u6027\u7684\u65b9\u6cd5<\/strong>\uff1a\u901a\u8fc7\u7c7b\u65b9\u6cd5\uff08\u5982<code>B()<\/code>\uff09\u4f7f\u7528<code>$this-&gt;A<\/code>\u4fee\u6539\u5c5e\u6027\u503c<\/li>\n\n\n\n<li><strong>\u503c\u6301\u4e45\u5316<\/strong>\uff1a\u4fee\u6539\u540e\u7684\u5c5e\u6027\u503c\u4f1a\u4e00\u76f4\u4fdd\u6301\uff0c\u76f4\u5230\u518d\u6b21\u4fee\u6539\u6216\u5bf9\u8c61\u9500\u6bc1<\/li>\n<\/ol><h3 class=\"wp-block-heading\">\u5b8c\u6574\u793a\u4f8b\uff1a<\/h3><pre class=\"wp-block-code\"><code>class MyClass {\n    \/\/ 1. \u5b9a\u4e49\u7c7b\u5c5e\u6027A\uff08\u9ed8\u8ba4\u503c\u4e3a0\uff09\n    public $A = 0;\n\n    \/\/ 2. \u5b9a\u4e49\u4fee\u6539A\u7684\u51fd\u6570B\n    public function B($newValue) {\n        $this-&gt;A = $newValue;\n    }\n\n    \/\/ \u8f85\u52a9\u51fd\u6570\uff1a\u663e\u793a\u5f53\u524dA\u7684\u503c\n    public function showA() {\n        echo \"\u5f53\u524dA\u7684\u503c: \" . $this-&gt;A . PHP_EOL;\n    }\n}\n\n\/\/ \u4f7f\u7528\u793a\u4f8b\n$obj = new MyClass();\n\n$obj-&gt;showA();  \/\/ \u8f93\u51fa\uff1a\u5f53\u524dA\u7684\u503c: 0\n\n\/\/ \u7b2c\u4e00\u6b21\u8c03\u7528B\u4fee\u6539A\u7684\u503c\n$obj-&gt;B(42);\n$obj-&gt;showA();  \/\/ \u8f93\u51fa\uff1a\u5f53\u524dA\u7684\u503c: 42\n\n\/\/ \u7b2c\u4e8c\u6b21\u8c03\u7528B\u4fee\u6539A\u7684\u503c\n$obj-&gt;B(100);\n$obj-&gt;showA();  \/\/ \u8f93\u51fa\uff1a\u5f53\u524dA\u7684\u503c: 100\n\n\/\/ \u76f4\u63a5\u8bbf\u95ee\u5c5e\u6027\u9a8c\u8bc1\necho \"\u6700\u7ec8\u503c: \" . $obj-&gt;A;  \/\/ \u8f93\u51fa\uff1a\u6700\u7ec8\u503c: 100<\/code><\/pre><h3 class=\"wp-block-heading\">\u5173\u952e\u70b9\u8bf4\u660e\uff1a<\/h3><ol class=\"wp-block-list\">\n<li><strong>\u5bf9\u8c61\u4e0a\u4e0b\u6587<\/strong>\uff1a<br>\u5fc5\u987b\u901a\u8fc7<code>$this<\/code>\u8bbf\u95ee\u5c5e\u6027\uff08<code>$this-&gt;A<\/code>\uff09\uff0c\u8fd9\u8868\u793a\u64cd\u4f5c\u5f53\u524d\u5b9e\u4f8b\u7684\u5c5e\u6027<\/li>\n\n\n\n<li><strong>\u4e0d\u540c\u5b9e\u4f8b\u72ec\u7acb<\/strong>\uff1a<br>\u6bcf\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\u62e5\u6709\u72ec\u7acb\u7684\u5c5e\u6027\u526f\u672c\uff1a<\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   $obj1 = new MyClass();\n   $obj2 = new MyClass();\n\n   $obj1-&gt;B(10);\n   $obj2-&gt;B(20);\n\n   echo $obj1-&gt;A; \/\/ \u8f93\u51fa10\uff08\u4e0d\u53d7obj2\u5f71\u54cd\uff09\n   echo $obj2-&gt;A; \/\/ \u8f93\u51fa20<\/code><\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u8bbf\u95ee\u63a7\u5236<\/strong>\uff08\u53ef\u9009\uff09\uff1a<br>\u4f7f\u7528\u8bbf\u95ee\u4fee\u9970\u7b26\u63a7\u5236\u53ef\u89c1\u6027\uff1a<\/li>\n<\/ol><pre class=\"wp-block-code\"><code>   class SecureClass {\n       private $A = 0; \/\/ \u79c1\u6709\u5c5e\u6027\uff0c\u4ec5\u7c7b\u5185\u90e8\u53ef\u8bbf\u95ee\n\n       public function getA() {\n           return $this-&gt;A; \/\/ \u901a\u8fc7\u516c\u6709\u65b9\u6cd5\u8bbf\u95ee\n       }\n\n       public function setA($value) {\n           $this-&gt;A = $value; \/\/ \u901a\u8fc7\u516c\u6709\u65b9\u6cd5\u4fee\u6539\n       }\n   }<\/code><\/pre><h3 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879\uff1a<\/h3><ul class=\"wp-block-list\">\n<li><strong>\u9759\u6001\u5c5e\u6027<\/strong>\uff1a\u82e5\u4f7f\u7528<code>static<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u5c5e\u6027\uff0c\u5219\u503c\u5728\u6240\u6709\u5b9e\u4f8b\u95f4\u5171\u4eab\uff08\u901a\u5e38\u4e0d\u9700\u8981\uff09<\/li>\n\n\n\n<li><strong>\u5bf9\u8c61\u6301\u4e45\u5316<\/strong>\uff1a\u5728Web\u8bf7\u6c42\u7ed3\u675f\u540e\u5bf9\u8c61\u4f1a\u9500\u6bc1\uff0c\u5982\u9700\u957f\u671f\u4fdd\u5b58\u9700\u914d\u5408Session\/\u6570\u636e\u5e93<\/li>\n\n\n\n<li><strong>\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316<\/strong>\uff1a\u53ef\u5728<code>__construct()<\/code>\u4e2d\u8bbe\u7f6e\u521d\u59cb\u503c\uff1a<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>  class MyClass {\n      public $A;\n\n      public function __construct() {\n          $this-&gt;A = 100; \/\/ \u521d\u59cb\u5316\u503c\n      }\n  }<\/code><\/pre><blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u7ed3\u8bba<\/strong>\uff1aPHP\u7c7b\u5c5e\u6027\u5929\u7136\u652f\u6301\u72b6\u6001\u6301\u4e45\u5316\uff0c\u901a\u8fc7\u6210\u5458\u51fd\u6570\u4fee\u6539\u5c5e\u6027\u540e\uff0c\u53ea\u8981\u4f7f\u7528\u540c\u4e00\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\uff0c\u540e\u7eed\u8bbf\u95ee\u90fd\u4f1a\u5f97\u5230\u6700\u65b0\u503c\u3002\u8fd9\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u57fa\u672c\u7279\u6027\u3002<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>\u5728PHP\u7c7b\u4e2d\uff0c\u5b8c\u5168\u53ef\u4ee5\u5b9e\u73b0\u60a8\u63cf\u8ff0\u7684\u529f\u80fd\u3002\u7c7b\u5c5e\u6027\uff08\u53d8\u91cf\uff09\u7684\u503c\u5728\u51fd\u6570\u8c03\u7528\u540e\u4f1a\u88ab\u6301\u4e45\u5316\u4fdd\u5b58\uff0c\u53ea\u8981\u60a8\u64cd\u4f5c\u7684\u662f\u540c\u4e00\u4e2a\u7c7b\u5b9e\u4f8b\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u539f\u7406\u548c\u793a\u4f8b\uff1a \u5b9e\u73b0\u539f\u7406\uff1a \u5b8c\u6574\u793a\u4f8b\uff1a \u5173\u952e\u70b9\u8bf4\u660e\uff1a \u6ce8\u610f\u4e8b\u9879\uff1a \u7ed3\u8bba\uff1aPHP\u7c7b\u5c5e\u6027\u5929\u7136\u652f\u6301\u72b6\u6001\u6301\u4e45\u5316\uff0c\u901a\u8fc7\u6210\u5458\u51fd\u6570\u4fee\u6539\u5c5e\u6027\u540e\uff0c\u53ea\u8981\u4f7f\u7528\u540c\u4e00\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\uff0c\u540e\u7eed\u8bbf\u95ee\u90fd\u4f1a\u5f97\u5230\u6700\u65b0\u503c\u3002\u8fd9\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u57fa\u672c..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":true},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-1293","my1js","type-my1js","status-publish","hentry","my1js2nav-jcyy"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"PHP\u7c7b\u5c5e\u6027\u6301\u4e45\u5316","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"PHP\u7c7b\u5c5e\u6027\u6301\u4e45\u5316"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/1293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=1293"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=1293"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=1293"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=1293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}