{"id":402,"date":"2025-06-10T19:54:23","date_gmt":"2025-06-10T11:54:23","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/402.html"},"modified":"2025-06-10T19:54:23","modified_gmt":"2025-06-10T11:54:23","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8php%e4%b8%ad%e5%ae%9a%e4%b9%89%e5%b8%b8%e9%87%8f","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/402.html","title":{"rendered":"\u5982\u4f55\u5728PHP\u4e2d\u5b9a\u4e49\u5e38\u91cf"},"content":{"rendered":"<p><body><\/p>\n<h2>&#27010;&#36848;<\/h2>\n<p>&#22312;PHP&#20013;&#23450;&#20041;&#24120;&#37327;&#23545;&#20110;&#21019;&#24314;&#31283;&#20581;&#19988;&#26131;&#20110;&#32500;&#25252;&#30340;&#24212;&#29992;&#31243;&#24207;&#33267;&#20851;&#37325;&#35201;&#12290;&#26412;&#25945;&#31243;&#25506;&#35752;&#20102;&#21508;&#31181;&#22768;&#26126;&#26041;&#27861;&#21644;&#26368;&#20339;&#23454;&#36341;&#12290;<\/p>\n<h2>PHP &#24120;&#37327;&#30340;&#20171;&#32461;<\/h2>\n<p>PHP&#20013;&#30340;&#24120;&#37327;&#26159;&#23450;&#20041;&#21518;&#19981;&#20250;&#22312;&#33050;&#26412;&#25191;&#34892;&#36807;&#31243;&#20013;&#25913;&#21464;&#30340;&#20540;&#12290;&#19982;&#21464;&#37327;&#19981;&#21516;&#65292;&#23427;&#20204;&#19981;&#20197;&ldquo;$&rdquo;&#24320;&#22836;&#12290;<code>$<\/code>&#31614;&#21517;&#36890;&#24120;&#20197;&#22823;&#20889;&#23383;&#27597;&#23450;&#20041;&#12290;&#26368;&#24120;&#29992;&#30340;&#26041;&#27861;&#26469;&#23450;&#20041;&#24120;&#37327;&#26159;&#20351;&#29992;const&#20851;&#38190;&#23383;&#12290;<code>define()<\/code>&#20989;&#25968;&#12290;&#21019;&#24314;&#24120;&#37327;&#30340;&#26368;&#31616;&#21333;&#26041;&#27861;&#22914;&#19979;&#65306;<\/p>\n<pre><code>define('SITE_URL', 'https:\/\/www.example.com');<\/code><\/pre>\n<p>&#20063;&#21487;&#20197;&#36890;&#36807;&#26816;&#26597;&#26159;&#21542;&#24050;&#32463;&#23450;&#20041;&#36807;&#24120;&#37327;&#26469;&#39564;&#35777;&#12290;<code>defined()<\/code>&#21151;&#33021;&#65306;<\/p>\n<pre><code>if (defined('SITE_URL')) {\n    echo 'SITE_URL is defined';\n}<\/code><\/pre>\n<h2>&#20351;&#29992;&#30340;&#26159;&#20160;&#20040;&#65311;<code>const<\/code>&#20851;&#38190;&#35789;&#26159;&#20160;&#20040;&#65311;<\/h2>\n<p>PHP&#20063;&#20801;&#35768;&#20351;&#29992;&#24120;&#37327;&#26469;&#23450;&#20041;&#65292;&#36890;&#36807;&#20351;&#29992;const&#20851;&#38190;&#23383;&#12290;<code>const<\/code>&#20851;&#38190;&#35789;&#65292;&#19982;&#20043;&#34892;&#20026;&#30053;&#26377;&#19981;&#21516;&#30340;&#26159;<code>define()<\/code>&#26368;&#22823;&#30340;&#19981;&#21516;&#22312;&#20110;<code>const<\/code>&#21487;&#20197;&#29992;&#20110;&#22312;&#32534;&#35793;&#26102;&#23450;&#20041;&#24120;&#37327;&#65292;&#36825;&#24847;&#21619;&#30528;&#23427;&#21487;&#20197;&#22312;&#31867;&#20869;&#37096;&#29992;&#20110;&#23450;&#20041;&#31867;&#24120;&#37327;&#12290;<\/p>\n<pre><code>const API_KEY = 'abcdef12345';<\/code><\/pre>\n<p>&#31867;&#24120;&#37327;&#21487;&#20197;&#36825;&#26679;&#23450;&#20041;&#21644;&#35775;&#38382;&#65306;<\/p>\n<pre><code>class Config {\n    const DB_HOST = 'localhost';\n}\necho Config::DB_HOST;<\/code><\/pre>\n<h2>&#39764;&#27861;&#24120;&#25968;<\/h2>\n<p>PHP &#25552;&#20379;&#20102;&#19968;&#32452;&#39044;&#23450;&#20041;&#30340;&#24120;&#37327;&#65292;&#36825;&#20123;&#24120;&#37327;&#26681;&#25454;&#23427;&#20204;&#34987;&#20351;&#29992;&#30340;&#20301;&#32622;&#32780;&#21464;&#21270;&#12290;&#36825;&#20123;&#34987;&#31216;&#20026;&#39764;&#26415;&#24120;&#37327;&#65292;&#30475;&#36215;&#26469;&#20687;&#36825;&#26679;&#65306;<code>__CONSTANT_NAME__<\/code>&#20363;&#22914;&#65292;<code>__FILE__<\/code>&#36820;&#22238;&#25991;&#20214;&#30340;&#23436;&#25972;&#36335;&#24452;&#21644;&#25991;&#20214;&#21517;&#12290;&#20197;&#19979;&#26159;&#39764;&#27861;&#24120;&#37327;&#20351;&#29992;&#30340;&#24555;&#36895;&#27010;&#35272;&#65306;<\/p>\n<pre><code>echo 'This file is located at ' . __FILE__;<\/code><\/pre>\n<h2>&#26465;&#20214;&#24120;&#37327;&#22768;&#26126;<\/h2>\n<p>&#26377;&#26102;&#65292;&#20320;&#38656;&#35201;&#26681;&#25454;&#26576;&#20123;&#26465;&#20214;&#26469;&#23450;&#20041;&#24120;&#37327;&#12290;&#20320;&#21487;&#20197;&#32452;&#21512;&#20351;&#29992;&#12290;<code>defined()<\/code>&#23545;&#19981;&#36215;&#65292;&#25105;&#19981;&#22826;&#26126;&#30333;&#24744;&#30340;&#24847;&#24605;&#65292;&#35831;&#24744;&#37325;&#26032;&#25551;&#36848;&#19968;&#19979;&#24744;&#30340;&#38382;&#39064;&#25110;&#38656;&#27714;&#12290;<code>define()<\/code>&#22312;&#26465;&#20214;&#35821;&#21477;&#19979;&#22768;&#26126;&#24120;&#37327;&#65306;<\/p>\n<pre><code>if (!defined('VERSION')) {\n    define('VERSION', '1.0.0');\n}<\/code><\/pre>\n<h2>&#22312;&#21629;&#21517;&#31354;&#38388;&#20013;&#20351;&#29992;&#24120;&#37327;<\/h2>\n<p>&#22312;PHP 5.3 &#21450;&#26356;&#39640;&#29256;&#26412;&#20013;&#65292;&#24120;&#37327;&#20063;&#21487;&#20197;&#23384;&#22312;&#20110;&#21629;&#21517;&#31354;&#38388;&#20869;&#65292;&#36825;&#26377;&#21161;&#20110;&#36991;&#20813;&#20195;&#30721;&#24211;&#20043;&#38388;&#30340;&#21517;&#31216;&#20914;&#31361;&#12290;&#21487;&#20197;&#20687;&#19979;&#38754;&#36825;&#26679;&#23450;&#20041;&#21644;&#35775;&#38382;&#21629;&#21517;&#31354;&#38388;&#20013;&#30340;&#24120;&#37327;&#65306;<\/p>\n<pre><code>namespace MyProject;\n\ndefine('MyProjectMAX_USERS', 100);\necho MAX_USERS;<\/code><\/pre>\n<p>&#25110;&#32773;&#20351;&#29992;<code>const<\/code>&#20851;&#38190;&#35789;&#65306;<\/p>\n<pre><code>namespace MyProject {\n    const MAX_USERS = 100;\n}\necho MyProjectMAX_USERS;<\/code><\/pre>\n<h2>&#26631;&#37327;&#31867;&#22411;&#21644;&#25968;&#32452;&#24120;&#37327;<\/h2>\n<p>&#22312;PHP 7.0&#21450;&#20197;&#19978;&#29256;&#26412;&#20013;&#65292;&#21487;&#20197;&#23450;&#20041;&#25968;&#32452;&#24120;&#37327;&#12290;<code>define()<\/code>&#22312;&#36825;&#19968;&#29256;&#26412;&#20043;&#21069;&#65292;&#21482;&#26377;&#26631;&#37327;&#25968;&#25454;&#65288;&#24067;&#23572;&#12289;&#25972;&#22411;&#12289;&#28014;&#28857;&#22411;&#21644;&#23383;&#31526;&#20018;&#65289;&#25165;&#33021;&#29992;&#20316;&#24120;&#37327;&#20540;&#65306;<\/p>\n<pre><code>define('ROLES', ['admin', 'editor', 'subscriber']);\necho ROLES[0]; \/\/ Outputs 'admin'<\/code><\/pre>\n<h2>&#35270;&#36317;&#26080;&#38459;<\/h2>\n<p><code>const<\/code>&#20063;&#25903;&#25345;&#21487;&#35265;&#24615;&#20462;&#39280;&#31526;&#65292;&#33258; PHP 7.1 &#36215;&#65292;&#20801;&#35768;&#24744;&#23450;&#20041;&#20844;&#20849;&#12289;&#31169;&#26377;&#25110;&#21463;&#20445;&#25252;&#30340;&#31867;&#24120;&#37327;&#65306;<\/p>\n<pre><code>class User {\n    public const STATUS_ACTIVE = 'active';\n    private const STATUS_PENDING = 'pending';\n    protected const STATUS_SUSPENDED = 'suspended';\n}<\/code><\/pre>\n<h2>&#23454;&#36341;&#20013;&#30340;&#24120;&#25968;&#29992;&#36884;<\/h2>\n<p>&#24120;&#37327;&#19981;&#20165;&#20165;&#29992;&#20110;&#37197;&#32622;&#20540;&#65292;&#23427;&#20204;&#36824;&#21487;&#20197;&#34920;&#31034;&#38169;&#35823;&#20195;&#30721;&#12289;&#29366;&#24577;&#26631;&#24535;&#12289;&#37325;&#35201;&#30340;&#25991;&#20214;&#36335;&#24452;&#31561;&#12290;&#20351;&#29992;&#24120;&#37327;&#21487;&#20197;&#20351;&#20320;&#30340;&#20195;&#30721;&#26356;&#26131;&#35835;&#19988;&#20943;&#23569;&#22240;&#20351;&#29992;&#39764;&#26415;&#23383;&#31526;&#20018;&#25110;&#25968;&#23383;&#32780;&#23548;&#33268;&#30340;&#38169;&#35823;&#39118;&#38505;&#12290;<\/p>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#22312;&#26412;&#25351;&#21335;&#20013;&#65292;&#24744;&#24050;&#32463;&#23398;&#20064;&#20102;&#23450;&#20041;PHP&#24120;&#37327;&#30340;&#19981;&#21516;&#26041;&#27861;&#21644;&#26368;&#20339;&#23454;&#36341;&#12290;&#24120;&#37327;&#26159;PHP&#32534;&#31243;&#20013;&#30340;&#22522;&#26412;&#32452;&#25104;&#37096;&#20998;&#65292;&#26377;&#21161;&#20110;&#32500;&#25252;&#25972;&#27905;&#19988;&#20581;&#22766;&#30340;&#20195;&#30721;&#12290;&#35831;&#35760;&#24471;&#26126;&#30830;&#21629;&#21517;&#23427;&#20204;&#24182;&#22312;&#25972;&#20010;&#24212;&#29992;&#31243;&#24207;&#20013;&#19968;&#33268;&#20351;&#29992;&#23427;&#20204;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#27010;&#36848; &#22312;PHP&#20013;&#23450;&#20041;&#24120;&#37327;&#23545;&#20110;&#21019;&#24314;&#31283;&#20581;&#19988;&#26131;&#20110;&#32500;&#25252;&#038;#30..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-402","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\/402","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=402"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=402"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=402"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}