{"id":605,"date":"2025-06-11T10:43:23","date_gmt":"2025-06-11T02:43:23","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/sjjg\/605.html"},"modified":"2025-06-11T10:43:23","modified_gmt":"2025-06-11T02:43:23","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8php%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%8f%af%e8%a7%81%e6%80%a7%ef%bc%88public%e3%80%81private%e3%80%81protected%ef%bc%89","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/605.html","title":{"rendered":"\u5982\u4f55\u5728PHP\u4e2d\u4f7f\u7528\u53ef\u89c1\u6027\uff08Public\u3001Private\u3001Protected\uff09"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;PHP&#20013;&#65292;&#21487;&#35265;&#24615;&#65288;public&#12289;private&#21644;protected&#65289;&#29992;&#20110;&#25511;&#21046;&#31867;&#25104;&#21592;&#30340;&#35775;&#38382;&#26435;&#38480;&#12290;&#36825;&#26377;&#21161;&#20110;&#32452;&#32455;&#20195;&#30721;&#65292;&#24182;&#30830;&#20445;&#31867;&#20013;&#30340;&#25968;&#25454;&#21644;&#26041;&#27861;&#21482;&#22312;&#39044;&#26399;&#30340;&#22320;&#26041;&#34987;&#35775;&#38382;&#12290;<\/p>\n<h3>&#20844;&#24320;&#65288;Public&#65289;<\/h3>\n<p>&#20844;&#26377;&#25104;&#21592;&#21487;&#20197;&#34987;&#20219;&#20309;&#22320;&#26041;&#35775;&#38382;&#65292;&#21253;&#25324;&#20854;&#20182;&#31867;&#12289;&#23545;&#35937;&#23454;&#20363;&#20197;&#21450;&#22806;&#37096;&#33050;&#26412;&#12290;<\/p>\n<pre><code class=\"language-php\">class MyClass {\n    public $publicVar = \"This is a public variable.\";\n\n    public function publicMethod() {\n        echo \"This is a public method.\";\n    }\n}<\/code><\/pre>\n<h3>&#31169;&#26377;&#65288;Private&#65289;<\/h3>\n<p>&#31169;&#26377;&#25104;&#21592;&#21482;&#33021;&#22312;&#23450;&#20041;&#23427;&#20204;&#30340;&#31867;&#20869;&#37096;&#35775;&#38382;&#65292;&#19981;&#33021;&#34987;&#22806;&#37096;&#31867;&#12289;&#23545;&#35937;&#23454;&#20363;&#25110;&#32773;&#22806;&#37096;&#33050;&#26412;&#35775;&#38382;&#12290;<\/p>\n<pre><code class=\"language-php\">class MyClass {\n    private $privateVar = \"This is a private variable.\";\n\n    private function privateMethod() {\n        echo \"This is a private method.\";\n    }\n}<\/code><\/pre>\n<h3>&#20445;&#25252;&#65288;Protected&#65289;<\/h3>\n<p>&#20445;&#25252;&#25104;&#21592;&#21482;&#33021;&#22312;&#23450;&#20041;&#23427;&#20204;&#30340;&#31867;&#20869;&#37096;&#35775;&#38382;&#65292;&#20063;&#21487;&#20197;&#22312;&#32487;&#25215;&#33258;&#35813;&#31867;&#30340;&#23376;&#31867;&#20013;&#35775;&#38382;&#12290;<\/p>\n<pre><code class=\"language-php\">class MyClass {\n    protected $protectedVar = \"This is a protected variable.\";\n\n    protected function protectedMethod() {\n        echo \"This is a protected method.\";\n    }\n}\n\nclass SubClass extends MyClass {\n    public function accessProtected() {\n        echo $this-&gt;protectedVar; \/\/ &#21487;&#20197;&#35775;&#38382;\n        $this-&gt;protectedMethod(); \/\/ &#21487;&#20197;&#35843;&#29992;\n    }\n}<\/code><\/pre>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#20551;&#35774;&#25105;&#20204;&#26377;&#19968;&#20010;<code>User<\/code>&#31867;&#65292;&#20854;&#20013;&#21253;&#21547;&#19968;&#20123;&#20844;&#20849;&#12289;&#31169;&#26377;&#21644;&#20445;&#25252;&#25104;&#21592;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ User.php\nclass User {\n    public $name;\n    private $age;\n    protected $email;\n\n    \/\/ &#26500;&#36896;&#20989;&#25968;\n    public function __construct($name, $age, $email) {\n        $this-&gt;name = $name;\n        $this-&gt;age = $age;\n        $this-&gt;email = $email;\n    }\n\n    \/\/ &#20844;&#20849;&#26041;&#27861;\n    public function introduce() {\n        return \"My name is {$this-&gt;name} and I am {$this-&gt;age} years old.\";\n    }\n\n    \/\/ &#31169;&#26377;&#26041;&#27861;\n    private function calculateAgeInDays() {\n        return $this-&gt;age * 365;\n    }\n\n    \/\/ &#20445;&#25252;&#26041;&#27861;\n    protected function getEmailDomain() {\n        return substr($this-&gt;email, strpos($this-&gt;email, '@') + 1);\n    }\n}<\/code><\/pre>\n<p>&#25105;&#20204;&#21487;&#20197;&#21019;&#24314;&#19968;&#20010;<code>Main<\/code>&#31867;&#26469;&#27979;&#35797;&#36825;&#20123;&#25104;&#21592;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ Main.php\nrequire 'User.php';\n\n$user = new User('John Doe', 30, 'john.doe@example.com');\n\necho $user-&gt;introduce(); \/\/ &#36755;&#20986;: My name is John Doe and I am 30 years old.\necho $user-&gt;calculateAgeInDays(); \/\/ &#36755;&#20986;: &#36825;&#37324;&#27809;&#26377;&#23454;&#29616;&#35745;&#31639;&#24180;&#40836;&#30340;&#26041;&#27861;\necho $user-&gt;getEmailDomain(); \/\/ &#36755;&#20986;: example.com<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#31034;&#20363;&#20013;&#65292;<code>$name<\/code>&#26159;&#20844;&#20849;&#30340;&#65292;&#21487;&#20197;&#22312;&#20219;&#20309;&#22320;&#26041;&#35775;&#38382;&#65307;<code>$age<\/code>&#26159;&#31169;&#26377;&#30340;&#65292;&#21482;&#33021;&#22312;<code>User<\/code>&#31867;&#20869;&#37096;&#35775;&#38382;&#65307;&#32780;<code>$email<\/code>&#26159;&#21463;&#20445;&#25252;&#30340;&#65292;&#21482;&#33021;&#22312;<code>User<\/code>&#31867;&#21450;&#20854;&#23376;&#31867;&#20013;&#35775;&#38382;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#27010;&#35272;<\/h2><p>&#29702;&#35299;&#23545;&#35937;&#21487;&#35265;&#24615;&#23545;&#20110;&#27491;&#30830;&#36827;&#34892;&#38754;&#21521;&#23545;&#35937;&#32534;&#31243;&#33267;&#20851;&#37325;&#35201;&#12290;&#22312;PHP&#20013;&#65292;&#21487;&#35265;&#24615;&#25351;&#30340;&#26159;&#23646;&#24615;&#21644;&#26041;&#27861;&#22312;&#31867;&#20869;&#37096;&#22914;&#20309;&#35775;&#38382;&#12290;&#26412;&#25945;&#31243;&#23558;&#25945;&#20320;&#20351;&#29992;&#20844;&#20849;&#12289;&#31169;&#26377;&#21644;&#20445;&#25252;&#30340;&#20851;&#38190;&#23383;&#65292;&#36825;&#20123;&#20851;&#38190;&#23383;&#20915;&#23450;&#20102;PHP&#31867;&#20013;&#30340;&#35775;&#38382;&#25511;&#21046;&#32423;&#21035;&#12290;&#20320;&#23558;&#23398;&#20064;&#23553;&#35013;&#30340;&#22522;&#30784;&#30693;&#35782;&#65292;&#28145;&#20837;&#25506;&#35752;&#27599;&#31181;&#21487;&#35265;&#24615;&#31867;&#22411;&#65292;&#24182;&#36890;&#36807;&#23454;&#38469;&#20195;&#30721;&#31034;&#20363;&#30475;&#21040;&#21487;&#35265;&#24615;&#22914;&#20309;&#24433;&#21709;&#20320;&#30340;PHP&#20195;&#30721;&#12290;<\/p><h2>&#20844;&#20849;&#21487;&#35265;&#24615;<\/h2><p>&#20844;&#24320;&#21487;&#35265;&#24615;&#24847;&#21619;&#30528;&#23646;&#24615;&#25110;&#26041;&#27861;&#21487;&#20197;&#20174;&#20219;&#20309;&#22320;&#26041;&#35775;&#38382;&#65292;&#21253;&#25324;&#31867;&#20869;&#37096;&#21644;&#22806;&#37096;&#12290;&#36825;&#26159;PHP&#40664;&#35748;&#20026;&#31867;&#25104;&#21592;&#35774;&#32622;&#30340;&#21487;&#35265;&#24615;&#65292;&#38500;&#38750;&#24744;&#26174;&#24335;&#22320;&#35774;&#32622;&#20102;&#19981;&#21516;&#30340;&#21487;&#35265;&#24615;&#32423;&#21035;&#12290;<\/p><p>&#36825;&#26159;&#19968;&#20010;&#22522;&#26412;&#30340;&#31034;&#20363;&#65292;&#23637;&#31034;&#20102;&#19968;&#20010;&#20844;&#20849;&#23646;&#24615;&#21644;&#26041;&#27861;&#65306;<\/p><pre><code>&lt;?php\nclass Car {\n    public $color = 'red';\n\n    public function getColor() {\n        return $this-&gt;color;\n    }\n}\n\n$myCar = new Car();\necho $myCar-&gt;getColor(); \/\/ Outputs: red\n?&gt;<\/code><\/pre><p>&#36825;&#20010;&#31616;&#21333;&#30340;&#31867;&#26377;&#19968;&#20010;&#20844;&#20849;&#23646;&#24615;&#12290;<code>$color<\/code>&#24182;&#19988;&#26377;&#19968;&#20010;&#20844;&#20849;&#26041;&#27861;<code>getColor()<\/code>&#20004;&#32773;&#37117;&#21487;&#20197;&#20174;&#22806;&#37096;&#31867;&#20043;&#22806;&#35775;&#38382;&#65292;&#22914;&#23454;&#20363;&#21270;&#26102;&#25152;&#35265;&#12290;<code>Car<\/code>&#23545;&#35937;&#21644;&#35843;&#29992;<code>getColor()<\/code>&#26041;&#27861;&#12290;<\/p><h2>&#31169;&#26377;&#21487;&#35265;&#24615;<\/h2><p>&#31169;&#26377;&#35775;&#38382;&#32423;&#21035;&#20165;&#20801;&#35768;&#23450;&#20041;&#35813;&#23646;&#24615;&#25110;&#26041;&#27861;&#30340;&#31867;&#20869;&#37096;&#36827;&#34892;&#35775;&#38382;&#12290;&#36825;&#24847;&#21619;&#30528;&#65292;&#24744;&#19981;&#33021;&#20174;&#31867;&#20043;&#22806;&#30452;&#25509;&#35775;&#38382;&#31169;&#26377;&#25104;&#21592;&#12290;&#36825;&#23545;&#20110;&#38544;&#34255;&#20869;&#37096;&#29366;&#24577;&#21644;&#19981;&#24212;&#35813;&#20316;&#20026;&#23545;&#35937;&#20844;&#24320;&#25509;&#21475;&#30340;&#19968;&#37096;&#20998;&#30340;&#24110;&#21161;&#26041;&#27861;&#26469;&#35828;&#38750;&#24120;&#26377;&#29992;&#12290;<\/p><p>&#20197;&#19979;&#26159;&#19968;&#20010;&#31169;&#26377;&#21487;&#35265;&#24615;&#30340;&#31034;&#20363;&#65306;<\/p><pre><code>&lt;?php\nclass Car {\n    private $color = 'red';\n\n    private function setColor($color) {\n        $this-&gt;color = $color;\n    }\n\n    public function getColor() {\n        return $this-&gt;color;\n    }\n}\n\n$myCar = new Car();\necho $myCar-&gt;getColor(); \/\/ Outputs: red\n\/\/$myCar-&gt;setColor('blue'); \/\/ Fatal error: Uncaught Error: Call to private method\n?&gt;<\/code><\/pre><p>&#22312;&#26356;&#26032;&#21518;&#30340;<code>Car<\/code>&#23545;&#19981;&#36215;&#65292;&#25105;&#26080;&#27861;&#29702;&#35299;&#24744;&#30340;&#38382;&#39064;&#12290;&#22914;&#26524;&#24744;&#26377;&#20854;&#20182;&#30340;&#38382;&#39064;&#65292;&#35831;&#37325;&#26032;&#25551;&#36848;&#19968;&#19979;&#65292;&#25105;&#20250;&#24456;&#20048;&#24847;&#24110;&#21161;&#24744;&#12290;<code>$color<\/code>&#25151;&#22320;&#20135;&#21644;&#35848;&#21028;&#12290;<code>setColor()<\/code>&#26041;&#27861;&#29616;&#22312;&#20026;&#31169;&#26377;&#12290;&#20844;&#24320;&#30340;&#26041;&#27861;<code>getColor()<\/code>&#20173;&#28982;&#21487;&#20197;&#20174;&#22806;&#38754;&#35775;&#38382;&#65292;&#20294;&#24744;&#26080;&#27861;&#30452;&#25509;&#26356;&#25913;&#39068;&#33394;&#23646;&#24615;&#12290;<\/p><h2>&#21463;&#20445;&#25252;&#30340;&#21487;&#35265;&#24615;<\/h2><p>&#20445;&#25252;&#30340;&#35775;&#38382;&#32423;&#21035;&#20171;&#20110;&#20844;&#20849;&#21644;&#31169;&#26377;&#20043;&#38388;&#12290;&#26631;&#35760;&#20026;protected&#30340;&#23646;&#24615;&#21644;&#26041;&#27861;&#21487;&#20197;&#22312;&#31867;&#20869;&#37096;&#12289;&#32487;&#25215;&#30340;&#31867;&#20197;&#21450;&#22806;&#37096;&#19990;&#30028;&#20043;&#22806;&#34987;&#35775;&#38382;&#12290;<\/p><p>&#20320;&#21487;&#20197;&#22914;&#20309;&#20351;&#29992;&#20445;&#25252;&#21487;&#35265;&#24615;&#65288;protected visibility&#65289;&#35753;&#23376;&#31867;&#35775;&#38382;&#20854;&#29238;&#31867;&#30340;&#23646;&#24615;&#25110;&#26041;&#27861;&#65306;<\/p><pre><code>&lt;?php\nclass Vehicle {\n    protected $color;\n\n    public function setColor($color) {\n        $this-&gt;color = $color;\n    }\n\n    protected function getColor() {\n        return $this-&gt;color;\n    }\n}\n\nclass Car extends Vehicle {\n    public function revealColor() {\n        return $this-&gt;getColor();\n    }\n}\n\n$myCar = new Car();\n$myCar-&gt;setColor('blue');\necho $myCar-&gt;revealColor(); \/\/ Outputs: blue\n?&gt;<\/code><\/pre><p>&#23545;&#19981;&#36215;&#65292;&#25105;&#19981;&#22826;&#26126;&#30333;&#20320;&#22312;&#35828;&#20160;&#20040;&#12290;<code>Vehicle<\/code>&#23545;&#19981;&#36215;&#65292;&#25105;&#19981;&#22826;&#26126;&#30333;&#24744;&#30340;&#24847;&#24605;&#12290;<code>$color<\/code>&#23427;&#34987;&#20445;&#25252;&#65292;&#26080;&#27861;&#30452;&#25509;&#20174;&#23454;&#20363;&#35775;&#38382;&#12290;<code>Car<\/code>&#28982;&#32780;&#65292;&#22240;&#20026;<code>Car<\/code>&#23427;&#26159;&#36229;&#31867;&#30340;&#19968;&#20010;&#23376;&#31867;&#12290;<code>Vehicle<\/code>&#23427;&#21487;&#20197;&#35775;&#38382;&#21463;&#20445;&#25252;&#30340;&#26041;&#27861;&#12290;<code>getColor()<\/code>&#22312;&#20854;&#33258;&#36523;&#30340;&#26041;&#27861;&#20013;<code>revealColor()<\/code>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><h2>&#39640;&#32423;&#29992;&#20363;<\/h2><p>&#24403;&#20320;&#23545;PHP&#30340;&#21487;&#35265;&#24615;&#21464;&#24471;&#36234;&#26469;&#36234;&#29087;&#24713;&#26102;&#65292;&#21487;&#20197;&#22312;&#26356;&#39640;&#32423;&#21035;&#30340;&#22330;&#26223;&#19979;&#24212;&#29992;&#36825;&#20123;&#21407;&#21017;&#65292;&#20363;&#22914;&#22312;&#35774;&#35745;&#27169;&#24335;&#21644;&#26694;&#26550;&#20013;&#12290;&#20197;&#19979;&#26159;&#19968;&#20123;&#31034;&#20363;&#65306;<\/p><pre><code>&lt;?php\n\/\/ ... \n\nuse some design pattern;\n\nclass AdvancedExample extends SomePattern {\n    \/\/ Implementation details\n}\n\n\/\/ ...\n?&gt;<\/code><\/pre><p>&#39640;&#32423;&#29992;&#20363;&#36890;&#24120;&#28041;&#21450;&#22312;&#25277;&#35937;&#31867;&#21644;&#25509;&#21475;&#20013;&#20351;&#29992;&#21463;&#20445;&#25252;&#30340;&#21487;&#35265;&#24615;&#65292;&#36825;&#20123;&#23454;&#20363;&#38656;&#35201;&#20005;&#26684;&#23450;&#20041;&#30340;API&#12290;&#36825;&#20123;&#20363;&#23376;&#36229;&#20986;&#20102;&#21021;&#23398;&#32773;&#27700;&#24179;&#65292;&#36827;&#20837;&#20102;&#20013;&#32423;&#21644;&#39640;&#32423;PHP&#32534;&#31243;&#39046;&#22495;&#12290;<\/p><h2>&#32467;&#35770;&#12290;<\/h2><p>&#32508;&#19978;&#25152;&#36848;&#65292;PHP&#30340;&#21487;&#35265;&#24615;&#25552;&#20379;&#20102;&#20445;&#25252;&#23545;&#35937;&#23436;&#25972;&#24615;&#30340;&#26041;&#24335;&#65292;&#36890;&#36807;&#25511;&#21046;&#20854;&#29366;&#24577;&#21644;&#34892;&#20026;&#30340;&#35775;&#38382;&#26469;&#23454;&#29616;&#36825;&#19968;&#28857;&#12290;&#36890;&#36807;&#20351;&#29992;public&#12289;private&#21644;protected&#20851;&#38190;&#23383;&#65292;&#20320;&#21487;&#20197;&#26500;&#24314;&#19968;&#20010;&#24378;&#22823;&#30340;&#19988;&#23433;&#20840;&#30340;&#23545;&#35937;&#23548;&#21521;&#24212;&#29992;&#31243;&#24207;&#12290;&#35831;&#35760;&#20303;&#65292;&#22312;&#27599;&#20010;&#31867;&#30340;&#26041;&#27861;&#21644;&#23646;&#24615;&#20013;&#20180;&#32454;&#32771;&#34385;&#21738;&#31181;&#21487;&#35265;&#24615;&#26159;&#26368;&#21512;&#36866;&#30340;&#65292;&#21516;&#26102;&#32771;&#34385;&#21040;&#23553;&#35013;&#24615;&#21644;&#32487;&#25215;&#30340;&#21407;&#21017;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; PHP &#20013;&#65292;<code>public<\/code>, <code>private<\/code> &#21644; <code>protected<\/code> &#26159;&#19977;&#31181;&#19981;&#21516;&#30340;&#35775;&#38382;&#32423;&#21035;&#65292;&#29992;&#20110;&#25511;&#21046;&#23545;&#35937;&#30340;&#21487;&#35265;&#24615;&#12290;<\/p>\n<ol>\n<li>\n<p><strong>public<\/strong>: &#20844;&#26377;&#23646;&#24615;&#21644;&#26041;&#27861;&#65306;&#36825;&#20123;&#23646;&#24615;&#21644;&#26041;&#27861;&#21487;&#20197;&#22312;&#20219;&#20309;&#22320;&#26041;&#34987;&#30452;&#25509;&#35775;&#38382;&#65292;&#21253;&#25324;&#31867;&#22806;&#12290;&#23427;&#20204;&#26159;&#38754;&#21521;&#23545;&#35937;&#32534;&#31243;&#20013;&#30340;&#26368;&#24120;&#35265;&#27169;&#24335;&#20043;&#19968;&#12290;<\/p>\n<\/li>\n<li>\n<p><strong>private<\/strong>: &#31169;&#26377;&#23646;&#24615;&#21644;&#26041;&#27861;&#65306;&#36825;&#20123;&#23646;&#24615;&#21644;&#26041;&#27861;&#21482;&#33021;&#22312;&#35813;&#31867;&#20869;&#37096;&#35775;&#38382;&#65292;&#19981;&#33021;&#20174;&#22806;&#37096;&#35775;&#38382;&#12290;&#36825;&#26159;&#20026;&#20102;&#20445;&#25252;&#25968;&#25454;&#23433;&#20840;&#65292;&#24182;&#38450;&#27490;&#26410;&#25480;&#26435;&#30340;&#35775;&#38382;&#12290;<\/p>\n<\/li>\n<li>\n<p><strong>protected<\/strong>: &#21487;&#20445;&#25252;&#23646;&#24615;&#21644;&#26041;&#27861;&#65306;&#36825;&#20123;&#23646;&#24615;&#21644;&#26041;&#27861;&#26082;&#21487;&#20197;&#34987;&#35813;&#31867;&#20869;&#30340;&#26041;&#27861;&#35775;&#38382;&#65292;&#20063;&#21487;&#20197;&#34987;&#23376;&#31867;&#35775;&#38382;&#12290;&#36825;&#26679;&#21487;&#20197;&#23454;&#29616;&#22810;&#24577;&#24615;&#21644;&#32487;&#25215;&#12290;<\/p>\n<\/li>\n<\/ol>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<pre><code class=\"language-php\">class MyClass {\n    public $property;\n    protected $protectedProperty;\n\n    \/\/ &#26500;&#36896;&#20989;&#25968;\n    public function __construct($value) {\n        $this-&gt;property = $value;\n    }\n\n    \/\/ &#20445;&#25252;&#30340;&#26041;&#27861;\n    public function protectedMethod() {\n        echo \"This is a protected method\";\n    }\n}\n\n\/\/ &#21019;&#24314;&#23454;&#20363;\n$myInstance = new MyClass(42);\n\n\/\/ &#35775;&#38382;&#31169;&#26377;&#23646;&#24615;\necho $myInstance-&gt;protectedProperty; \/\/ &#36755;&#20986;: null (&#22240;&#20026;&#31169;&#26377;)\n\n\/\/ &#35775;&#38382;&#20844;&#26377;&#23646;&#24615;\necho $myInstance-&gt;property; \/\/ &#36755;&#20986;: 42\n\n\/\/ &#35843;&#29992;&#20445;&#25252;&#26041;&#27861;\n$myInstance-&gt;protectedMethod(); \/\/ &#36755;&#20986;: This is a protected method<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65306;<\/p>\n<ul>\n<li>&#31867; <code>MyClass<\/code> &#23454;&#29616;&#20102; <code>public<\/code> &#23646;&#24615;&#21644;&#26041;&#27861;&#12290;<\/li>\n<li>&#31867; <code>MyClass<\/code> &#30340;&#26500;&#36896;&#20989;&#25968;&#23454;&#29616;&#20102; <code>protected<\/code> &#26041;&#27861;&#12290;<\/li>\n<li>&#31867; <code>MyClass<\/code> &#30340;&#20844;&#20849;&#23646;&#24615; <code>property<\/code> &#21644;&#31169;&#26377;&#23646;&#24615; <code>protectedProperty<\/code> &#37117;&#34987;&#27491;&#30830;&#22320;&#35775;&#38382;&#21644;&#22788;&#29702;&#12290;<\/li>\n<\/ul>\n<p>&#36890;&#36807;&#36825;&#31181;&#26041;&#24335;&#65292;&#20320;&#21487;&#20197;&#26681;&#25454;&#38656;&#35201;&#36873;&#25321;&#36866;&#24403;&#30340;&#35775;&#38382;&#32423;&#21035;&#26469;&#25511;&#21046;&#23545;&#35937;&#30340;&#21487;&#35265;&#24615;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312;PHP&#20013;&#65292;&#21487;&#35265;&#24615;&#65288;public&#12289;private&#21644;protected&#65289;&#29992;&#20110;&#25511;&#038;#2..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[41],"tuisongtax":[],"class_list":["post-605","my1js","type-my1js","status-publish","hentry","my1js2nav-sjjg"],"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":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/605","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=605"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=605"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=605"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}