{"id":612,"date":"2025-06-11T10:54:13","date_gmt":"2025-06-11T02:54:13","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/sjjg\/612.html"},"modified":"2025-06-11T10:54:13","modified_gmt":"2025-06-11T02:54:13","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8php%e4%b8%ad%e5%88%9b%e5%bb%ba%e4%b8%8d%e5%8f%af%e5%8f%98%e5%af%b9%e8%b1%a1","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/612.html","title":{"rendered":"\u5982\u4f55\u5728PHP\u4e2d\u521b\u5efa\u4e0d\u53ef\u53d8\u5bf9\u8c61"},"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;&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;&#21487;&#20197;&#36890;&#36807;&#20197;&#19979;&#20960;&#31181;&#26041;&#27861;&#23454;&#29616;&#65306;<\/p>\n<h3>&#26041;&#27861;&#19968;&#65306;&#20351;&#29992; <code>final<\/code> &#20851;&#38190;&#23383;&#21644; <code>readonly<\/code> &#23646;&#24615;<\/h3>\n<pre><code class=\"language-php\">class ImmutableObject {\n    private $value;\n\n    public function __construct($value) {\n        $this-&gt;value = $value;\n    }\n\n    public function getValue() {\n        return $this-&gt;value;\n    }\n}\n\n$immutable = new ImmutableObject(10);\necho $immutable-&gt;getValue(); \/\/ &#36755;&#20986;: 10<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;<code>ImmutableObject<\/code> &#31867;&#26159;&#19981;&#21487;&#21464;&#30340;&#65292;&#22240;&#20026;&#23427;&#30340;&#26500;&#36896;&#20989;&#25968;&#26159;&#31169;&#26377;&#30340;&#65292;&#24182;&#19988;&#25152;&#26377;&#23646;&#24615;&#37117;&#26159;&#21482;&#35835;&#30340;&#12290;<\/p>\n<h3>&#26041;&#27861;&#20108;&#65306;&#20351;&#29992; <code>const<\/code> &#20851;&#38190;&#23383;&#21644;&#38745;&#24577;&#23646;&#24615;<\/h3>\n<pre><code class=\"language-php\">class ImmutableObject {\n    const VALUE = 10;\n\n    public static function getInstance() {\n        return new self();\n    }\n}\n\n$instance = ImmutableObject::getInstance();\necho ImmutableObject::VALUE; \/\/ &#36755;&#20986;: 10<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;<code>VALUE<\/code> &#26159;&#19968;&#20010;&#24120;&#37327;&#65292;&#34920;&#31034;&#19981;&#21487;&#21464;&#30340;&#23545;&#35937;&#30340;&#20540;&#12290;<code>getInstance<\/code> &#26041;&#27861;&#36820;&#22238;&#19968;&#20010;&#23454;&#20363;&#21270;&#30340;&#23545;&#35937;&#65292;&#30830;&#20445;&#20102;&#23545;&#35937;&#26159;&#19981;&#21487;&#21464;&#30340;&#12290;<\/p>\n<h3>&#26041;&#27861;&#19977;&#65306;&#20351;&#29992;&#38381;&#21253;&#26469;&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;<\/h3>\n<pre><code class=\"language-php\">function createImmutableObject($value) {\n    return function () use ($value) {\n        return $value;\n    };\n}\n\n$immutable = createImmutableObject(20);\necho $immutable(); \/\/ &#36755;&#20986;: 20<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;<code>createImmutableObject<\/code> &#20989;&#25968;&#36820;&#22238;&#19968;&#20010;&#38381;&#21253;&#65292;&#35813;&#38381;&#21253;&#25509;&#21463;&#19968;&#20010;&#21442;&#25968;&#24182;&#36820;&#22238;&#35813;&#21442;&#25968;&#12290;&#36825;&#20010;&#38381;&#21253;&#21487;&#20197;&#34987;&#35270;&#20026;&#19968;&#20010;&#19981;&#21487;&#21464;&#30340;&#23545;&#35937;&#65292;&#22240;&#20026;&#23427;&#19981;&#20250;&#25913;&#21464;&#20854;&#29366;&#24577;&#12290;<\/p>\n<h3>&#31034;&#20363;&#20195;&#30721;&#30456;&#20851;&#27493;&#39588;<\/h3>\n<ol>\n<li>\n<p><strong>&#23450;&#20041;&#19981;&#21487;&#21464;&#31867;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-php\">class ImmutableObject {\n   private $value;\n\n   public function __construct($value) {\n       $this-&gt;value = $value;\n   }\n\n   public function getValue() {\n       return $this-&gt;value;\n   }\n}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;&#30340;&#23454;&#20363;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-php\">$immutable = new ImmutableObject(10);\necho $immutable-&gt;getValue(); \/\/ &#36755;&#20986;: 10<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#20351;&#29992;&#24120;&#37327;&#21644;&#38745;&#24577;&#23646;&#24615;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-php\">class ImmutableObject {\n   const VALUE = 10;\n\n   public static function getInstance() {\n       return new self();\n   }\n}\n\n$instance = ImmutableObject::getInstance();\necho ImmutableObject::VALUE; \/\/ &#36755;&#20986;: 10<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#20351;&#29992;&#38381;&#21253;&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;<\/strong>&#65306;<\/p>\n<pre><code class=\"language-php\">function createImmutableObject($value) {\n   return function () use ($value) {\n       return $value;\n   };\n}\n\n$immutable = createImmutableObject(20);\necho $immutable(); \/\/ &#36755;&#20986;: 20<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>&#36890;&#36807;&#36825;&#20123;&#26041;&#27861;&#65292;&#20320;&#21487;&#20197;&#36731;&#26494;&#22320;&#22312;PHP&#20013;&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;&#12290;&#36873;&#25321;&#21738;&#31181;&#26041;&#27861;&#21462;&#20915;&#20110;&#20320;&#30340;&#20855;&#20307;&#38656;&#27714;&#21644;&#20195;&#30721;&#39118;&#26684;&#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>&#19981;&#21487;&#21464;&#23545;&#35937;&#26159;&#25351;&#22312;&#21019;&#24314;&#21518;&#29366;&#24577;&#26080;&#27861;&#20462;&#25913;&#30340;&#23545;&#35937;&#12290;&#36825;&#19968;&#27010;&#24565;&#23545;&#20110;&#32534;&#20889;&#26356;&#21487;&#39044;&#27979;&#21644;&#21487;&#38752;&#30340;&#36719;&#20214;&#38750;&#24120;&#26377;&#30410;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#26576;&#20123;&#21407;&#21017;&#21644;&#25216;&#26415;&#26469;&#23454;&#29616;&#23427;&#12290;&#26412;&#25945;&#31243;&#23558;&#20174;&#22522;&#30784;&#21040;&#39640;&#32423;&#25945;&#20320;&#22914;&#20309;&#20351;&#29992;PHP&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;&#12290;<\/p><h2>&#20171;&#32461;&#19981;&#21487;&#21464;&#24615;<\/h2><p>&#22312;&#28145;&#20837;&#25506;&#35752;&#22914;&#20309;&#25805;&#20316;&#20043;&#21069;&#65292;&#35753;&#25105;&#20204;&#20808;&#28548;&#28165;&#19968;&#19979;&#19981;&#21487;&#21464;&#23545;&#35937;&#30340;&#27010;&#24565;&#21450;&#20854;&#37325;&#35201;&#24615;&#12290;&#19981;&#21487;&#21464;&#23545;&#35937;&#26159;&#25351;&#19968;&#20010;&#31867;&#30340;&#23454;&#20363;&#65292;&#19968;&#26086;&#21019;&#24314;&#21518;&#23601;&#19981;&#33021;&#20877;&#25913;&#21464;&#20854;&#29366;&#24577;&#12290;&#20219;&#20309;&#21487;&#33021;&#25913;&#21464;&#20854;&#29366;&#24577;&#30340;&#26041;&#27861;&#37117;&#20250;&#36820;&#22238;&#19968;&#20010;&#26032;&#30340;&#23454;&#20363;&#65292;&#35813;&#23454;&#20363;&#20855;&#26377;&#26356;&#25913;&#21518;&#30340;&#20540;&#12290;&#19982;&#27492;&#19981;&#21516;&#30340;&#26159;&#65292;&#21487;&#21464;&#23545;&#35937;&#21487;&#20197;&#22312;&#21019;&#24314;&#21518;&#34987;&#20462;&#25913;&#12290;<\/p><p>&#21487;&#21464;&#24615;&#22312;&#35768;&#22810;&#20989;&#25968;&#24335;&#32534;&#31243;&#35821;&#35328;&#20013;&#26159;&#26680;&#24515;&#27010;&#24565;&#65292;&#36825;&#24471;&#30410;&#20110;&#23427;&#20351;&#24471;&#20195;&#30721;&#26356;&#23481;&#26131;&#29702;&#35299;&#21644;&#20943;&#23569;&#21103;&#20316;&#29992;&#21644;&#24182;&#21457;&#38382;&#39064;&#30340;&#39118;&#38505;&#12290;&#22312;PHP&#20013;&#65292;&#20316;&#20026;&#20027;&#35201;&#30340;&#21487;&#21464;&#24615;&#35821;&#35328;&#65292;&#23454;&#29616;&#21487;&#21464;&#24615;&#38656;&#35201;&#32426;&#24459;&#24615;&#21644;&#28165;&#26224;&#30340;&#35774;&#35745;&#27169;&#24335;&#12290;<\/p><h2>&#21019;&#24314;&#22522;&#26412;&#19981;&#21487;&#21464;&#23545;&#35937;<\/h2><p>&#20026;&#20102;&#21019;&#24314;&#19968;&#20010;&#19981;&#21487;&#21464;&#23545;&#35937;&#65292;&#20320;&#38656;&#35201;&#35774;&#35745;&#20320;&#30340;&#31867;&#65292;&#20351;&#24471;&#19968;&#26086;&#23545;&#35937;&#34987;&#26500;&#36896;&#20986;&#26469;&#65292;&#20854;&#29366;&#24577;&#23601;&#19981;&#33021;&#20877;&#25913;&#21464;&#12290;&#19968;&#31181;&#22522;&#26412;&#30340;&#26041;&#27861;&#21487;&#33021;&#26159;&#36825;&#26679;&#30340;&#65306;<\/p><pre><code>&lt;?php\nclass ImmutablePoint {\n    private float $x;\n    private float $y;\n\n    public function __construct(float $x, float $y) {\n        $this-&gt;x = $x;\n        $this-&gt;y = $y;\n    }\n\n    public function getX(): float {\n        return $this-&gt;x;\n    }\n\n    public function getY(): float {\n        return $this-&gt;y;\n    }\n\n    public function moveTo(float $newX, float $newY): ImmutablePoint {\n        return new self($newX, $newY);\n    }\n}\n\n\/\/ Usage\n$point = new ImmutablePoint(1.0, 2.0);\n$newPoint = $point-&gt;moveTo(3.0, 4.0);\n?&gt;<\/code><\/pre><p>&#22312;&#19978;&#36848;&#20363;&#23376;&#20013;&#65292;<code>ImmutablePoint<\/code>&#23427;&#19981;&#25552;&#20379;&#20219;&#20309;&#22312;&#23454;&#20363;&#21270;&#21518;&#25913;&#21464;&#29366;&#24577;&#30340;&#26041;&#27861;&#12290;&#38656;&#35201;&#36827;&#34892;&#29366;&#24577;&#21464;&#21270;&#30340;&#26041;&#27861;&#20250;&#36820;&#22238;&#19968;&#20010;&#26032;&#30340;&#23454;&#20363;&#12290;<\/p><h2>&#22788;&#29702;&#20869;&#37096;&#25968;&#32452;<\/h2><p>&#22312;&#22788;&#29702;&#25105;&#20204;&#30340;&#19981;&#21487;&#21464;&#31867;&#20013;&#30340;&#25968;&#32452;&#25110;&#23545;&#35937;&#26102;&#65292;&#25105;&#20204;&#24517;&#39035;&#30830;&#20445;&#36825;&#20123;&#20063;&#26159;&#19981;&#21487;&#21464;&#30340;&#65292;&#21542;&#21017;&#21487;&#33021;&#20250;&#26080;&#24847;&#20013;&#24341;&#21457;&#21103;&#20316;&#29992;&#12290;&#19968;&#20010;&#24120;&#35265;&#30340;&#38169;&#35823;&#26159;&#25552;&#20379;&#23545;&#36825;&#20123;&#20869;&#37096;&#32467;&#26500;&#30340;&#30452;&#25509;&#35775;&#38382;&#65292;&#20363;&#22914;&#65306;<\/p><pre><code>\/\/ Incorrect way to expose internal arrays - MUTABLE\nclass MutableWrapper {\n    private array $data;\n\n    public function __construct(array $data) {\n        $this-&gt;data = $data;\n    }\n\n    public function getData(): array {\n        return $this-&gt;data; \/\/ This is mutable\n    }\n\n    ... \/\/ Other code\n}\n\n\/\/ Correct way using immutability pattern\nclass ImmutableWrapper {\n    private array $data;\n\n    public function __construct(array $data) {\n        $this-&gt;data = $data;\n    }\n\n    public function getData(): array {\n        return $this-&gt;data;\n    }\n\n    public function withData(array $newData): ImmutableWrapper {\n        return new self(array_merge($this-&gt;data, $newData));\n    }\n}\n?&gt;<\/code><\/pre><p>&#22312;&#20462;&#27491;&#30340;&#31034;&#20363;&#20013;&#65292;&#20219;&#20309;&#26356;&#25913;&#37117;&#24212;&#34987;&#35760;&#24405;&#19979;&#26469;&#12290;<code>data<\/code>&#36825;&#20250;&#23548;&#33268;&#19968;&#20010;&#26032;&#30340;&#23545;&#35937;&#34987;&#36820;&#22238;&#65292;&#32780;&#21407;&#22987;&#23545;&#35937;&#30340;&#25968;&#32452;&#19981;&#21463;&#24433;&#21709;&#12290;<\/p><h2>&#39640;&#32423;&#19981;&#21487;&#21464;&#24615;&#27169;&#24335;<\/h2><p>&#20026;&#20102;&#23454;&#29616;&#26356;&#39640;&#32423;&#30340;&#19981;&#21487;&#21464;&#24615;&#65292;&#20320;&#21487;&#20197;&#35774;&#35745;&#19968;&#20010;&#31867;&#26469;&#20197;&#19981;&#21487;&#21464;&#30340;&#26041;&#24335;&#22788;&#29702;&#20854;&#20381;&#36182;&#39033;&#12290;&#36825;&#24847;&#21619;&#30528;&#19981;&#20165;&#35813;&#31867;&#30340;&#23646;&#24615;&#26412;&#36523;&#24517;&#39035;&#26159;&#19981;&#21487;&#21464;&#30340;&#65292;&#20219;&#20309;&#24341;&#29992;&#30340;&#23545;&#35937;&#20063;&#24517;&#39035;&#26159;&#19981;&#21487;&#21464;&#30340;&#12290;&#35201;&#23454;&#29616;&#36825;&#19968;&#28857;&#65292;&#30830;&#20445;&#20351;&#29992;&#19981;&#21487;&#21464;&#23545;&#35937;&#20316;&#20026;&#20381;&#36182;&#39033;&#25110;&#22312;&#24517;&#35201;&#26102;&#36827;&#34892;&#38450;&#21355;&#22797;&#21046;&#12290;<\/p><pre><code>&lt;?php\nclass ImmutableDependency {\n    private ImmutablePoint $point;\n\n    ... \/\/ Other code\n\n    public function __construct(ImmutablePoint $point) {\n        \/\/ Make a copy to ensure immutability\n        $this-&gt;point = new ImmutablePoint($point-&gt;getX(), $point-&gt;getY());\n    }\n\n    ... \/\/ Other code\n}\n\n\/\/ Usage\n$originalPoint = new ImmutablePoint(1.0, 2.0);\n$dependencyObject = new ImmutableDependency($originalPoint);\n\n\/\/ $originalPoint remains unchanged even if $dependencyObject changes internally\n?&gt;<\/code><\/pre><p>&#36890;&#36807;&#20351;&#29992;&#36825;&#31181;&#26041;&#27861;&#65292;&#24744;&#23454;&#38469;&#19978;&#30830;&#20445;&#20102;&#23545;&#35937;&#21450;&#20854;&#25972;&#20010;&#23545;&#35937;&#22270;&#30340;&#19981;&#21487;&#21464;&#24615;&#12290;<\/p><h2>&#22312;&#23454;&#36341;&#20013;&#20351;&#29992;&#19981;&#21464;&#24615;&#65288;Immutability&#65289;<\/h2><p>&#22312;&#23454;&#36341;&#20013;&#65292;&#21487;&#21464;&#24615;&#21487;&#20197;&#29992;&#26469;&#21019;&#24314;&#20581;&#22766;&#12289;&#21487;&#32500;&#25252;&#21644;&#24182;&#21457;&#30340;&#36719;&#20214;&#12290;PHP 8 &#24341;&#20837;&#20102; immutability&#12290;<code>readonly<\/code>&#20851;&#38190;&#35789;&#65292;&#21487;&#20197;&#20351;&#24378;&#21046;&#19981;&#21487;&#21464;&#24615;&#21464;&#24471;&#31245;&#24494;&#23481;&#26131;&#19968;&#20123;&#12290;&#27492;&#22806;&#65292;&#35831;&#32771;&#34385;&#20351;&#29992;&#20540;&#23545;&#35937;&#65292;&#25317;&#25265;&#36820;&#22238;&#26032;&#23454;&#20363;&#32780;&#19981;&#26159;&#20462;&#25913;&#29616;&#26377;&#23454;&#20363;&#65292;&#20248;&#20808;&#36873;&#25321;&#32452;&#21512;&#32780;&#38750;&#32487;&#25215;&#26041;&#27861;&#65292;&#22312;&#24517;&#35201;&#26102;&#65292;&#23545;&#21487;&#21464;&#20381;&#36182;&#36827;&#34892;&#28145;&#25335;&#36125;&#12290;<\/p><h2>&#32467;&#35770;<\/h2><p>&#22312;PHP&#20013;&#65292;&#19981;&#21487;&#21464;&#24615;&#26159;&#19968;&#31181;&#24378;&#22823;&#30340;&#27010;&#24565;&#65292;&#22312;&#23454;&#29616;&#21518;&#21487;&#20197;&#35753;&#20320;&#30340;&#20195;&#30721;&#26356;&#20855;&#26377;&#39044;&#27979;&#24615;&#21644;&#21487;&#35835;&#24615;&#12290;&#34429;&#28982;PHP&#26412;&#36523;&#19981;&#25903;&#25345;&#19981;&#21487;&#21464;&#24615;&#65292;&#20294;&#20320;&#21487;&#20197;&#36890;&#36807;&#20180;&#32454;&#30340;&#35774;&#35745;&#31867;&#21644;&#23545;&#35937;&#32452;&#21512;&#26469;&#23454;&#29616;&#23427;&#12290;&#36981;&#24490;&#26412;&#25945;&#31243;&#20013;&#30340;&#21407;&#21017;&#65292;&#20320;&#23558;&#33021;&#22815;&#32534;&#20889;&#26356;&#21152;&#23433;&#20840;&#19988;&#21487;&#38752;&#30340;PHP&#24212;&#29992;&#31243;&#24207;&#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;&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;&#26159;&#36890;&#36807;&#20351;&#29992;&#24037;&#21378;&#20989;&#25968;&#21644;&#31867;&#23646;&#24615;&#26469;&#23454;&#29616;&#30340;&#12290;&#19981;&#21487;&#21464;&#23545;&#35937;&#24847;&#21619;&#30528;&#19968;&#26086;&#23454;&#20363;&#21270;&#65292;&#20854;&#29366;&#24577;&#23601;&#19981;&#33021;&#25913;&#21464;&#12290;<\/p>\n<p>&#20197;&#19979;&#26159;&#22914;&#20309;&#22312; PHP &#20013;&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;&#30340;&#19968;&#20010;&#20363;&#23376;&#65306;<\/p>\n<pre><code class=\"language-php\">class MyClass {\n    private $value;\n\n    public function __construct($initialValue) {\n        $this-&gt;value = $initialValue;\n    }\n\n    \/\/ &#20801;&#35768;&#26356;&#25913;&#20540;&#30340;&#26041;&#27861;\n    public function setValue($newValue) {\n        $this-&gt;value = $newValue;\n    }\n\n    \/\/ &#19981;&#20801;&#35768;&#26356;&#25913;&#20540;&#30340;&#26041;&#27861;\n    public function getValue() {\n        return $this-&gt;value;\n    }\n}\n\n\/\/ &#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;\n$myObject = new MyClass(10);\n\n\/\/ &#21487;&#20197;&#26356;&#25913;&#20540;\n$myObject-&gt;setValue(20);\n\n\/\/ &#20294;&#26159;&#19981;&#33021;&#26356;&#25913;&#20540;\necho $myObject-&gt;getValue(); \/\/ &#36755;&#20986;&#65306;10\n\n\/\/ &#29616;&#22312;&#21487;&#20197;&#26356;&#25913;&#20540;\n$myObject-&gt;setValue(30);<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#23450;&#20041;&#20102;&#19968;&#20010;&#21517;&#20026; <code>MyClass<\/code> &#30340;&#31867;&#65292;&#24182;&#22312;&#20854;&#20013;&#20351;&#29992;&#20102;&#31169;&#26377;&#21464;&#37327; <code>$value<\/code> &#26469;&#23384;&#20648;&#20540;&#12290;&#28982;&#21518;&#25105;&#20204;&#25552;&#20379;&#20102;&#20004;&#20010;&#26041;&#27861;&#65306;<\/p>\n<ul>\n<li><code>__construct()<\/code>&#65306;&#21021;&#22987;&#21270;&#26041;&#27861;&#65292;&#29992;&#20110;&#35774;&#32622;&#21021;&#22987;&#20540;&#12290;<\/li>\n<li><code>setValue()<\/code> &#21644; <code>getValue()<\/code>&#65306;&#20801;&#35768;&#26356;&#25913;&#20540;&#30340;&#26041;&#27861;&#65292;&#20294;&#19981;&#20801;&#35768;&#30452;&#25509;&#26356;&#25913;&#20540;&#12290;<\/li>\n<\/ul>\n<p>&#36825;&#26679;&#25105;&#20204;&#23601;&#23454;&#29616;&#20102;&#19981;&#21487;&#21464;&#30340;&#23545;&#35937;&#12290;&#29616;&#22312;&#20320;&#21487;&#20197;&#30475;&#21040;&#65292;&#24403;&#25105;&#20204;&#23581;&#35797;&#26356;&#25913; <code>$myObject<\/code> &#30340;&#20540;&#26102;&#65292;&#23427;&#20250;&#36820;&#22238;&#21407;&#26469;&#30340;&#20540;&#65292;&#32780;&#19981;&#26159;&#26032;&#30340;&#20540;&#12290;&#36825;&#26159;&#22240;&#20026;&#23427;&#34987;&#22768;&#26126;&#20026;&#19981;&#21487;&#21464;&#23545;&#35937;&#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;&#21019;&#24314;&#19981;&#21487;&#21464;&#23545;&#35937;&#21487;&#20197;&#36890;&#36807;&#20197;&#19979;&#038;..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[41],"tuisongtax":[],"class_list":["post-612","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\/612","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=612"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=612"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=612"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}