{"id":441,"date":"2025-06-10T20:29:47","date_gmt":"2025-06-10T12:29:47","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/441.html"},"modified":"2025-06-10T20:29:47","modified_gmt":"2025-06-10T12:29:47","slug":"php%e4%b8%ad%e7%9a%84%e5%8f%af%e9%80%89%e7%b1%bb%e5%9e%8b%e5%a3%b0%e6%98%8e%ef%bc%9a%e6%8f%90%e9%ab%98%e4%bb%a3%e7%a0%81%e5%8f%af%e9%9d%a0%e6%80%a7","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/441.html","title":{"rendered":"PHP\u4e2d\u7684\u53ef\u9009\u7c7b\u578b\u58f0\u660e\uff1a\u63d0\u9ad8\u4ee3\u7801\u53ef\u9760\u6027"},"content":{"rendered":"<p><body><\/p>\n<h2>&#20171;&#32461;<\/h2>\n<p>PHP&#65292;&#20197;&#20854;&#23485;&#26494;&#30340;&#31867;&#22411;&#22768;&#26126;&#32780;&#38395;&#21517;&#65292;&#27491;&#36880;&#28176;&#37319;&#32435;&#22686;&#24378;&#20195;&#30721;&#21487;&#38752;&#24615;&#30340;&#26032;&#29305;&#24615;&#12290;&#22312;PHP 7&#20013;&#24341;&#20837;&#30340;&#21487;&#36873;&#31867;&#22411;&#22768;&#26126;&#20316;&#20026;&#24037;&#20855;&#65292;&#26377;&#21161;&#20110;&#26500;&#24314;&#26356;&#21152;&#25972;&#27905;&#12289;&#28165;&#26224;&#21644;&#22362;&#22266;&#30340;&#20195;&#30721;&#24211;&#12290;<\/p>\n<h2>&#24320;&#22987;&#23398;&#20064;&#31867;&#22411;&#65288;Getting Started with Types&#65289;<\/h2>\n<p>&#31867;&#22411;&#22768;&#26126;&#65292;&#20063;&#31216;&#20026;&#31867;&#22411;&#27880;&#37322;&#65292;&#20801;&#35768;&#24320;&#21457;&#20154;&#21592;&#22312;&#20989;&#25968;&#35843;&#29992;&#12289;&#20989;&#25968;&#36820;&#22238;&#31867;&#22411;&#21644;&#31867;&#23646;&#24615;&#20013;&#25351;&#23450;&#39044;&#26399;&#30340;&#25968;&#25454;&#31867;&#22411;&#12290;&#20197;&#19979;&#26159;&#19968;&#20010;&#31616;&#30701;&#30340;&#20363;&#23376;&#65306;<\/p>\n<pre><code>function add(int $a, int $b): int {\n    return $a + $b;\n}\n<\/code><\/pre>\n<p>&#35813;&#21151;&#33021;&#35201;&#27714;&#20004;&#20010;&#21442;&#25968;&#22343;&#20026;&#25972;&#25968;&#65292;&#24182;&#19988;&#36820;&#22238;&#30340;&#20540;&#20063;&#26159;&#25972;&#25968;&#12290;<\/p>\n<h2>&#26631;&#37327;&#31867;&#22411;&#22768;&#26126;<\/h2>\n<p>&#26631;&#37327;&#31867;&#22411;&#22312;PHP 7&#20013;&#26159;&#19968;&#20010;&#37325;&#35201;&#30340;&#22686;&#24378;&#21151;&#33021;&#65292;&#23427;&#20204;&#20801;&#35768;&#20989;&#25968;&#35201;&#27714;&#21442;&#25968;&#30340;&#31867;&#22411;&#20026;int&#12289;float&#12289;string&#25110;bool&#12290;&#20197;&#19979;&#26159;&#20351;&#29992;&#23427;&#20204;&#30340;&#26041;&#27861;&#65306;<\/p>\n<pre><code>function setAge(int $age) {\n    echo \"You are {$age} years old.\";\n}\n<\/code><\/pre>\n<h2>&#20005;&#26684;&#31867;&#22411;&#26816;&#26597;&#19982;&#24378;&#21046;&#24615;&#31867;&#22411;&#26816;&#26597;<\/h2>\n<p>PHP 7 &#24341;&#20837;&#20102;&#20005;&#26684;&#30340;&#31867;&#22411;&#26816;&#26597;&#27169;&#24335;&#12290;&#35813;&#27169;&#24335;&#36890;&#36807;&#22768;&#26126;&#26469;&#21551;&#29992;&#12290;<code>declare(strict_types=1);<\/code>&#22312;&#25991;&#20214;&#30340;&#39030;&#37096;&#65292;&#24378;&#21046;PHP&#36981;&#24490;&#25351;&#23450;&#30340;&#25968;&#25454;&#31867;&#22411;&#65292;&#21542;&#21017;&#23427;&#20250;&#25243;&#20986;&#19968;&#20010;TypeError&#24322;&#24120;&#12290;&#20197;&#19979;&#26159;&#34892;&#20026;&#19978;&#30340;&#19981;&#21516;&#20043;&#22788;&#65306;<\/p>\n<pre><code>\/\/ Coercive mode\nfunction addNumbers($a, $b): int {\n    return $a + $b;\n}\n\naddNumbers('3', 4.2); \/\/ This will work, outputting 7\n\n\/\/ Strict mode\ndeclare(strict_types=1);\n\nfunction addNumbersStrict($a, $b): int {\n    return $a + $b;\n}\n\naddNumbersStrict('3', 4.2); \/\/ TypeError\n<\/code><\/pre>\n<p>&#22312;&#24378;&#21046;&#27169;&#24335;&#19979;&#65292;PHP &#23558;&#23613;&#21147;&#21305;&#37197;&#22768;&#26126;&#31867;&#22411;&#65307;&#32780;&#22312;&#20005;&#26684;&#27169;&#24335;&#19979;&#65292;&#21017;&#19981;&#20250;&#36825;&#26679;&#20570;&#12290;<\/p>\n<h2>&#32852;&#21512;&#31867;&#22411;<\/h2>\n<p>PHP 8 &#24341;&#20837;&#20102;&#32852;&#21512;&#31867;&#22411;&#65292;&#20801;&#35768;&#21442;&#25968;&#25110;&#36820;&#22238;&#31867;&#22411;&#25509;&#21463;&#22810;&#31181;&#31867;&#22411;&#12290;&#36825;&#22312;&#22810;&#24577;&#22330;&#26223;&#20013;&#38750;&#24120;&#26377;&#29992;&#65306;<\/p>\n<pre><code>function processInput(string|int $data) {\n    if (is_int($data)) {\n        echo \"Integer received: $data\";\n    } else {\n        echo \"String received: $data\";\n    }\n}\n<\/code><\/pre>\n<h2>&#22797;&#26434;&#31867;&#22411;&#65306;&#25968;&#32452;&#21644;&#23545;&#35937;<\/h2>\n<p>&#38500;&#20102;&#22522;&#26412;&#31867;&#22411;&#20043;&#22806;&#65292;PHP&#36824;&#25903;&#25345;&#22797;&#26434;&#30340;&#31867;&#22411;&#22768;&#26126;&#65292;&#20363;&#22914;&#25968;&#32452;&#21644;&#23545;&#35937;&#12290;&#36825;&#20123;&#21487;&#20197;&#22914;&#20309;&#20351;&#29992;&#65306;<\/p>\n<pre><code>function configure(array $settings) {\n    \/\/ Process settings array\n}\n\nclass User {}\n\nfunction newUser(User $user) {\n    \/\/ Process User object\n}\n<\/code><\/pre>\n<h2>&#21487;&#36873;&#20540;&#21644;&#40664;&#35748;&#20540;<\/h2>\n<p>&#21487;&#36873;&#31867;&#22411;&#65292;&#29992;&#38382;&#21495;&#21069;&#32512;&#20110;&#31867;&#22411;&#22768;&#26126;&#65292;&#20801;&#35768;&#21442;&#25968;&#20026;&#25351;&#23450;&#31867;&#22411;&#30340;&#20540;&#25110;null&#12290;&#20197;&#19979;&#26159;&#20351;&#29992;&#21487;&#36873;&#31867;&#22411;&#30340;&#31034;&#20363;&#65306;<\/p>\n<pre><code>function setProfile(string $name, ?string $bio) {\n    if (is_null($bio)) {\n        echo \"Welcome, $name!\";\n    } else {\n        echo \"Welcome, $name! Read their bio: $bio\";\n    }\n}\n<\/code><\/pre>\n<h2>&#25151;&#20135;&#31867;&#22411;&#22768;&#26126;<\/h2>\n<p>&#22312;PHP 7.4&#20013;&#65292;&#24341;&#20837;&#20102;&#23646;&#24615;&#31867;&#22411;&#22768;&#26126;&#65292;&#25552;&#20379;&#20102;&#20026;&#31867;&#21644;&#23545;&#35937;&#23646;&#24615;&#22768;&#26126;&#31867;&#22411;&#30340;&#21151;&#33021;&#12290;&#31034;&#20363;&#65306;<\/p>\n<pre><code>class Item {\n    public int $id;\n    public string $name;\n}\n<\/code><\/pre>\n<h2>&#39640;&#32423;&#65306;&#21464;&#38271;&#21442;&#25968;&#21644;&#31867;&#22411;<\/h2>\n<p>&#21464;&#38271;&#21442;&#25968;&#21015;&#34920;&#20063;&#21487;&#20197;&#21033;&#29992;&#31867;&#22411;&#22768;&#26126;&#65292;&#30830;&#20445;&#20256;&#20837;&#21464;&#37327;&#38271;&#24230;&#21442;&#25968;&#21015;&#34920;&#20013;&#30340;&#25152;&#26377;&#20540;&#37117;&#26159;&#21516;&#19968;&#31181;&#31867;&#22411;&#65306;<\/p>\n<pre><code>function addAll(int ...$numbers): int {\n    return array_sum($numbers);\n}\n<\/code><\/pre>\n<h2>&#22312;&#21311;&#21517;&#20989;&#25968;&#20013;&#20351;&#29992;&#31867;&#22411;&#12290;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#65292;&#20063;&#31216;&#20026;&#38381;&#21253;&#65292;&#21487;&#20197;&#36890;&#36807;&#20197;&#19979;&#26041;&#24335;&#21463;&#30410;&#20110;&#31867;&#22411;&#22768;&#26126;&#65306;<\/p>\n<pre><code>\n$arrayOfNumbers = [1, 2, 3];\n\n$arrayOfNumbers = array_map(\n   function (int $number): int {\n       return $number * 2;\n   },\n   $arrayOfNumbers\n);<\/code><\/pre>\n<h2>&#21518;&#21521;&#20860;&#23481;&#24615;<\/h2>\n<p>&#26032;&#30340;&#31867;&#22411;&#22768;&#26126;&#36890;&#24120;&#20855;&#26377;&#21521;&#21518;&#20860;&#23481;&#24615;&#65292;&#20294;&#22312;&#24341;&#20837;&#21040;&#36951;&#30041;&#20195;&#30721;&#26102;&#24212;&#35880;&#24910;&#34892;&#20107;&#12290;&#22312;&#20351;&#29992;&#38750;&#27491;&#24335;&#31867;&#22411;&#30340;&#20195;&#30721;&#20013;&#21487;&#33021;&#20250;&#20986;&#29616;&#31867;&#22411;&#38169;&#35823;&#12290;<\/p>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>PHP&#31867;&#22411;&#22768;&#26126;&#22686;&#24378;&#20102;&#20195;&#30721;&#30340;&#20581;&#22766;&#24615;&#21644;&#28165;&#26224;&#24230;&#65292;&#36890;&#36807;&#24341;&#20837;&#19968;&#23618;&#24378;&#21270;&#24320;&#21457;&#32773;&#30340;&#24847;&#22270;&#24182;&#30830;&#20445;&#20195;&#30721;&#25353;&#39044;&#26399;&#24037;&#20316;&#30340;&#26041;&#24335;&#12290;&#26377;&#22810;&#31181;&#36873;&#39033;&#21487;&#20379;&#36873;&#25321;&#65292;&#20174;&#22522;&#26412;&#31867;&#22411;&#21040;&#22797;&#26434;&#31867;&#22411;&#65292;&#36825;&#20123;&#24037;&#20855;&#20026;&#32534;&#20889;&#25972;&#27905;&#12289;&#21487;&#39044;&#27979;&#30340;PHP&#20195;&#30721;&#25552;&#20379;&#20102;&#23453;&#36149;&#30340;&#36164;&#28304;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#20171;&#32461; PHP&#65292;&#20197;&#20854;&#23485;&#26494;&#30340;&#31867;&#22411;&#22768;&#26126;&#32780;&#38395;&#21517;&#65292;&#27491;&#36880;&#28176;&#038;#37..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-441","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":"","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\/441","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=441"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=441"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=441"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}