{"id":442,"date":"2025-06-10T20:30:40","date_gmt":"2025-06-10T12:30:40","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/442.html"},"modified":"2025-06-10T20:30:40","modified_gmt":"2025-06-10T12:30:40","slug":"php%e4%b8%ad%e7%9a%84%e7%a9%ba%e5%80%bc%e5%90%88%e5%b9%b6%e8%bf%90%e7%ae%97%e7%ac%a6%ef%bc%9a%e4%bc%98%e9%9b%85%e7%9a%84%e9%bb%98%e8%ae%a4%e5%80%bc%e5%a4%84%e7%90%86","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/442.html","title":{"rendered":"PHP\u4e2d\u7684\u7a7a\u503c\u5408\u5e76\u8fd0\u7b97\u7b26\uff1a\u4f18\u96c5\u7684\u9ed8\u8ba4\u503c\u5904\u7406"},"content":{"rendered":"<p><body><\/p>\n<h2>&#20171;&#32461;<\/h2>\n<p>&#22312;PHP 7&#20013;&#24341;&#20837;&#30340;&#31354;&#20540;&#21512;&#24182;&#36816;&#31639;&#31526;&#25552;&#20379;&#20102;&#19968;&#31181;&#31616;&#27905;&#19988;&#24178;&#20928;&#30340;&#26041;&#24335;&#26469;&#20351;&#29992;&#40664;&#35748;&#20540;&#65292;&#24403;&#21464;&#37327;&#20026;null&#26102;&#12290;<\/p>\n<h2>&#24320;&#22987;&#20351;&#29992;&ldquo;?&rdquo;&#65311;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;null coalescing&#36816;&#31639;&#31526;&#65288;??&#65289;&#26159;&#19968;&#31181;&#35821;&#27861;&#31958;&#26500;&#36896;&#65292;&#31616;&#21270;&#20102;&#26816;&#26597;&#21464;&#37327;&#23384;&#22312;&#24615;&#21644;&#20540;&#30340;&#27493;&#39588;&#12290;&#22312;PHP 7&#20043;&#21069;&#65292;&#24320;&#21457;&#32773;&#36890;&#24120;&#20250;&#20351;&#29992;isset()&#20989;&#25968;&#32467;&#21512;&#19977;&#20803;&#26465;&#20214;&#26469;&#23454;&#29616;&#31867;&#20284;&#30340;&#32467;&#26524;&#12290;&#35753;&#25105;&#20204;&#30475;&#30475;&#36825;&#20010;&#22522;&#26412;&#20195;&#30721;&#31034;&#20363;&#65306;<\/p>\n<pre><code>$username = isset($_GET['user']) ? $_GET['user'] : 'anonymous';\n<\/code><\/pre>\n<p>&#20351;&#29992;&#31354;&#20540;&#21512;&#24182;&#36816;&#31639;&#31526;&#21518;&#65292;&#36825;&#31616;&#21270;&#20026;&#65306;<\/p>\n<pre><code>$username = $_GET['user'] ?? 'anonymous';\n<\/code><\/pre>\n<p>&#36825;&#31181;&#26041;&#27861;&#31435;&#21363;&#31616;&#21270;&#20102;&#20195;&#30721;&#65292;&#20351;&#20854;&#26356;&#26131;&#35835;&#19988;&#26131;&#20110;&#32500;&#25252;&#12290;<\/p>\n<h2>&#32487;&#32493;&#20351;&#29992;&#31354;&#20540;&#21512;&#24182;&#12290;<\/h2>\n<p>&#25805;&#20316;&#21592;&#19981;&#20165;&#38480;&#20110;&#31616;&#21333;&#30340;&#21464;&#37327;&#26816;&#26597;&#65292;&#36824;&#21487;&#20197;&#19982;&#22810;&#20010;&#36816;&#31639;&#31526;&#19968;&#36215;&#20351;&#29992;&#65292;&#20174;&#24038;&#21040;&#21491;&#35780;&#20272;&#30452;&#21040;&#25214;&#21040;&#38750;&#31354;&#20540;&#12290;&#35753;&#25105;&#20204;&#36890;&#36807;&#19968;&#20010;&#39640;&#32423;&#31034;&#20363;&#26469;&#36827;&#19968;&#27493;&#25506;&#35752;&#65306;<\/p>\n<pre><code>$username = $_GET['user'] ?? $_SESSION['user'] ?? 'anonymous';\n<\/code><\/pre>\n<p>&#36825;&#20010;&#36807;&#31243;&#20250;&#36941;&#21382; $_GET &#21644; $_SESSION &#25968;&#32452;&#65292;&#26368;&#21518;&#22312;&#25152;&#26377;&#20854;&#20182;&#24773;&#20917;&#37117;&#22833;&#36133;&#26102;&#25191;&#34892;&#19968;&#20010;&#23454;&#38469;&#30340;&#26465;&#20214;&#21028;&#26029;&#12290;<\/p>\n<p>&#23427;&#20063;&#19982;&#20989;&#25968;&#21644;&#26041;&#27861;&#35843;&#29992;&#26080;&#32541;&#38598;&#25104;&#12290;&#20363;&#22914;&#65306;<\/p>\n<pre><code>$username = getUserFromDatabase($id) ?? 'fallback';\n<\/code><\/pre>\n<p>&#22312;&#36825;&#31181;&#24773;&#20917;&#19979;&#65292;&#22914;&#26524;&#35843;&#29992;getUserFromDatabase($id)&#36820;&#22238;null&#65292;&#21017;&#20351;&#29992;&ldquo;fallback&rdquo;&#12290;<\/p>\n<h2>&#19982;&#22797;&#26434;&#32467;&#26500;&#24037;&#20316;<\/h2>\n<p>null coalescing operator &#26159;&#22810;&#21151;&#33021;&#30340;&#65292;&#21487;&#20197;&#30452;&#25509;&#24212;&#29992;&#20110;&#22810;&#32500;&#25968;&#32452;&#21644;&#29978;&#33267; JSON &#23545;&#35937;&#12290;&#32771;&#34385;&#20197;&#19979;&#31034;&#20363;&#65306;<\/p>\n<pre><code>$configValue = $appConfig['database']['host'] ?? 'localhost';\n<\/code><\/pre>\n<p>&#35753;&#25105;&#20204;&#36827;&#19968;&#27493;&#25506;&#35752;&#29289;&#20307;&#65306;<\/p>\n<pre><code>$profilePic = $user-&gt;getProfile()-&gt;getPicture() ?? 'default.jpg';\n<\/code><\/pre>\n<p>&#36825;&#20010;&#20195;&#30721;&#20248;&#38597;&#22320;&#23581;&#35797;&#33719;&#21462;&#22836;&#20687;&#65292;&#22914;&#26524;&#27809;&#26377;&#36820;&#22238;&#21017;&#40664;&#35748;&#20351;&#29992;&#40664;&#35748;&#20540;&#12290;<\/p>\n<h2>&#32467;&#21512;PHP 7&#30340;&#20854;&#20182;&#29305;&#24615;<\/h2>\n<p>PHP 7 &#24341;&#20837;&#20102;&#20854;&#20182;&#35821;&#27861;&#25913;&#36827;&#65292;&#22914;&#29992;&#20110;&#27604;&#36739;&#30340;&#31661;&#22836;&#36816;&#31639;&#31526;&#65288;&lt;=&gt;&#65289;&#12290;&#32467;&#21512;&#20351;&#29992;&#31354;&#20540;&#21512;&#24182;&#36816;&#31639;&#31526;&#21487;&#20197;&#29983;&#25104;&#24378;&#22823;&#30340;&#34920;&#36798;&#24335;&#12290;&#20363;&#22914;&#65306;<\/p>\n<pre><code>$status = $session['status'] ?? 'unknown';\n\/\/ Now use the spaceship operator for comparison\necho (0 &lt;=&gt; $status); \/\/ Outputs -1, 0, or 1\n<\/code><\/pre>\n<h2>&#29616;&#23454;&#19990;&#30028;&#22330;&#26223;<\/h2>\n<p>&#22312;&#23454;&#38469;&#24212;&#29992;&#20013;&#65292;&#25317;&#25265;&#31354;&#20540;&#21512;&#24182;&#36816;&#31639;&#31526;&#24847;&#21619;&#30528;&#20851;&#27880;&#19994;&#21153;&#36923;&#36753;&#32780;&#19981;&#26159;&#26679;&#26495;&#26816;&#26597;&#12290;&#23427;&#23588;&#20854;&#36866;&#29992;&#20110;&#28041;&#21450;&#37197;&#32622;&#12289;&#34920;&#21333;&#12289;API&#20197;&#21450;&#26465;&#20214;&#26174;&#31034;&#30340;&#22330;&#26223;&#12290;&#35813;&#36816;&#31639;&#31526;&#22312;&#29616;&#20195;PHP&#24320;&#21457;&#27969;&#31243;&#20013;&#24120;&#24120;&#25104;&#20026;&#19981;&#21487;&#25110;&#32570;&#30340;&#19968;&#37096;&#20998;&#12290;<\/p>\n<p>&#20363;&#22914;&#65292;&#22312;&#22788;&#29702;API&#36755;&#20837;&#26102;&#65306;<\/p>\n<pre><code>$apiResponse = processApiResponse($inputData) ?? [];\n<\/code><\/pre>\n<p>&#20363;&#22914;&#65292;&#20351;&#29992;GUI&#35774;&#32622;&#35821;&#35328;&#33258;&#36866;&#24212;&#65306;<\/p>\n<pre><code>$labelText = $languageLabels[$currentLanguage]['submit'] ?? $languageLabels['en']['submit'] ?? 'Submit';\n<\/code><\/pre>\n<h2>&#22909;&#30340;&#23454;&#36341;&#19982;&#38519;&#38449;<\/h2>\n<p>&#23613;&#31649;&#20854;&#23454;&#29992;&#24615;&#24456;&#24378;&#65292;&#20294;&#22312;&#26576;&#20123;&#24773;&#20917;&#19979;&#65292;null coalescing&#36816;&#31639;&#31526;&#24182;&#19981;&#36866;&#29992;&#12290;&#23427;&#19981;&#24212;&#34987;&#29992;&#20316;&#29992;&#25143;&#25968;&#25454;&#30340;&#27491;&#30830;&#39564;&#35777;&#21644;&#28165;&#29702;&#65292;&#20063;&#19981;&#24212;&#36807;&#24230;&#20351;&#29992;&#22312;&#22797;&#26434;&#30340;&#26465;&#20214;&#20013;&#65292;&#22240;&#20026;&#36825;&#21487;&#33021;&#38656;&#35201;&#26356;&#28165;&#26224;&#30340;&#36923;&#36753;&#20197;&#32500;&#25252;&#20195;&#30721;&#12290;&#23601;&#20687;&#32534;&#31243;&#20013;&#30340;&#20219;&#20309;&#24037;&#20855;&#19968;&#26679;&#65292;&#26126;&#26234;&#22320;&#20351;&#29992;&#23427;&#33267;&#20851;&#37325;&#35201;&#12290;<\/p>\n<h2>&#24615;&#33021;&#24433;&#21709;<\/h2>\n<p>&#22312;&#24615;&#33021;&#26041;&#38754;&#65292;&#31354;&#20540;&#21512;&#24182;&#36816;&#31639;&#31526;&#26159;&#20010;&#19981;&#38169;&#30340;&#36873;&#25321;&#12290;&#36890;&#24120;&#24773;&#20917;&#19979;&#65292;&#23427;&#27604;&#32467;&#21512;&#20351;&#29992;isset()&#21644;&#19977;&#20803;&#36816;&#31639;&#31526;&#26469;&#29983;&#25104;&#36739;&#23569;&#30340;opcode&#35201;&#24555;&#12290;&#35753;&#25105;&#20204;&#36890;&#36807;&#19968;&#20010;&#26102;&#38388;&#27979;&#35797;&#26469;&#36827;&#34892;&#39564;&#35777;&#65306;<\/p>\n<pre><code>\/\/ Traditional isset with ternary operator\n$start = microtime(true);\n$result = isset($data['key']) ? $data['key'] : 'default';\n$timeTaken = microtime(true) - $start;\n\n\/\/ Using null coalescing operator\n$start = microtime(true);\n$result = $data['key'] ?? 'default';\n$timeTaken = microtime(true) - $start;\n<\/code><\/pre>\n<p>&#20351;&#29992;&#31354;&#20540;&#32852;&#21512;&#36816;&#31639;&#31526;&#21487;&#33021;&#20250;&#35753;&#20320;&#27880;&#24847;&#21040;&#36731;&#24494;&#20294;&#19968;&#33268;&#30340;&#36895;&#24230;&#20248;&#21183;&#12290;<\/p>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;null coalescing&#36816;&#31639;&#31526;&#31616;&#21270;&#20102;&#40664;&#35748;&#20540;&#36171;&#20540;&#65292;&#24182;&#26377;&#21161;&#20110;&#32534;&#20889;&#26356;&#31616;&#27905;&#30340;&#20195;&#30721;&#12290;&#38543;&#30528;PHP&#19981;&#26029;&#36827;&#21270;&#65292;&#37319;&#29992;&#36825;&#20123;&#21151;&#33021;&#19981;&#20165;&#21487;&#20197;&#25552;&#39640;&#35821;&#35328;&#25928;&#29575;&#65292;&#36824;&#33021;&#22686;&#24378;&#24320;&#21457;&#32773;&#30340;&#34920;&#36798;&#33021;&#21147;&#21644;&#24847;&#22270;&#12290;&#31616;&#32780;&#35328;&#20043;&#65292;&#36825;&#20010;&#36816;&#31639;&#31526;&#33021;&#20248;&#21270;&#25105;&#20204;&#20316;&#20026;PHP&#24320;&#21457;&#32773;&#27599;&#22825;&#36827;&#34892;&#30340;&#35821;&#27861;&#33310;&#36424;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#20171;&#32461; &#22312;PHP 7&#20013;&#24341;&#20837;&#30340;&#31354;&#20540;&#21512;&#24182;&#36816;&#31639;&#31526;&#25552;&#20379;&#20102;&#19968;&#31181;&#038;#..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-442","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\/442","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=442"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=442"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=442"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}