{"id":73835,"date":"2024-02-26T11:07:52","date_gmt":"2024-02-26T03:07:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=73835"},"modified":"2024-02-26T11:08:09","modified_gmt":"2024-02-26T03:08:09","slug":"php-8%e7%9a%84%e6%96%b0%e7%89%b9%e6%80%a7%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/73835.html","title":{"rendered":"PHP 8\u7684\u65b0\u7279\u6027\u6709\u54ea\u4e9b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-73836\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/02\/img-O1Q8fkCEdsPMuJE7wtTjEMxR.png?x-oss-process=image\/auto-orient,1\/format,webp\" width=\"600\" height=\"342\" alt=\"PHP 8\u7684\u65b0\u7279\u6027\u6709\u54ea\u4e9b\" \/><\/p>\n<p>### PHP 8\u7684\u65b0\u7279\u6027\u6709\u54ea\u4e9b<\/p>\n<p>\u5728PHP 8\u7684\u4e16\u754c\u4e2d\uff0c<strong>JIT\u7f16\u8bd1\u5668\u3001\u8054\u5408\u7c7b\u578b\u3001\u547d\u540d\u53c2\u6570\u3001\u6784\u9020\u5668\u5c5e\u6027\u63d0\u5347\u3001\u5339\u914d\u8868\u8fbe\u5f0f<\/strong>\u3001\u4ee5\u53ca<strong>\u9519\u8bef\u5904\u7406\u7684\u6539\u8fdb<\/strong>\u7ad9\u5728\u4e86\u6280\u672f\u9769\u65b0\u7684\u524d\u6cbf\u3002\u7279\u522b\u662f\uff0c<strong>JIT\u7f16\u8bd1\u5668<\/strong>\u4e3aPHP\u5e26\u6765\u4e86\u524d\u6240\u672a\u6709\u7684\u6027\u80fd\u63d0\u5347\uff0c\u901a\u8fc7\u5373\u65f6\u7f16\u8bd1\u6280\u672f\u5c06PHP\u4ee3\u7801\u8f6c\u6362\u6210\u673a\u5668\u7801\uff0c\u663e\u8457\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u6267\u884c\u6548\u7387\u3002\u8fd9\u4e0d\u4ec5\u4e3a\u5f00\u53d1\u8005\u5e26\u6765\u4e86\u66f4\u5feb\u7684\u5f00\u53d1\u4f53\u9a8c\uff0c\u4e5f\u4e3a\u7ec8\u7aef\u7528\u6237\u63d0\u4f9b\u4e86\u66f4\u52a0\u6d41\u7545\u7684\u4f7f\u7528\u4f53\u9a8c\u3002<\/p>\n<p>PHP 8\u662fPHP\u5386\u53f2\u4e0a\u4e00\u4e2a\u91cd\u5927\u7684\u66f4\u65b0\uff0c\u5b83\u5f15\u5165\u4e86\u8bb8\u591a\u65b0\u7279\u6027\u548c\u6539\u8fdb\uff0c\u65e8\u5728\u63d0\u9ad8\u4ee3\u7801\u7684\u7f16\u5199\u6548\u7387\u3001\u6267\u884c\u6027\u80fd\u4ee5\u53ca\u5b89\u5168\u6027\u3002\u4ee5\u4e0b\u662fPHP 8\u7684\u4e00\u4e9b\u4e3b\u8981\u65b0\u7279\u6027\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n<p>#### \u4e00\u3001JIT\u7f16\u8bd1\u5668<\/p>\n<p>PHP 8\u7684\u4e00\u4e2a\u6700\u5927\u4eae\u70b9\u662f\u5f15\u5165\u4e86JIT\uff08Just In Time\uff09\u7f16\u8bd1\u6280\u672f\u3002JIT\u7f16\u8bd1\u5668\u53ef\u4ee5\u5c06PHP\u4ee3\u7801\u5373\u65f6\u7f16\u8bd1\u6210\u673a\u5668\u7801\uff0c\u4ece\u800c\u5728\u8fd0\u884c\u65f6\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u3002\u8fd9\u610f\u5473\u7740PHP\u4ee3\u7801\u7684\u6267\u884c\u901f\u5ea6\u5c06\u663e\u8457\u63d0\u5347\uff0c\u7279\u522b\u662f\u5728\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002JIT\u7f16\u8bd1\u5668\u7684\u5f15\u5165\u4e0d\u4ec5\u63d0\u9ad8\u4e86PHP\u7684\u6267\u884c\u6548\u7387\uff0c\u4e5f\u4f7f\u5f97PHP\u5728\u66f4\u591a\u6027\u80fd\u654f\u611f\u7684\u5e94\u7528\u573a\u666f\u4e2d\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n<p>#### \u4e8c\u3001\u8054\u5408\u7c7b\u578b<\/p>\n<p>\u5728PHP 7\u4e2d\uff0c\u7c7b\u578b\u58f0\u660e\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u548c\u7a33\u5b9a\u6027\u3002PHP 8\u8fdb\u4e00\u6b65\u6269\u5c55\u4e86\u8fd9\u4e00\u529f\u80fd\uff0c\u5f15\u5165\u4e86\u8054\u5408\u7c7b\u578b\u3002\u8fd9\u610f\u5473\u7740\u51fd\u6570\u6216\u65b9\u6cd5\u7684\u53c2\u6570\u3001\u8fd4\u56de\u503c\u73b0\u5728\u53ef\u4ee5\u58f0\u660e\u4e3a\u591a\u4e2a\u7c7b\u578b\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\uff0c\u5927\u5927\u63d0\u9ad8\u4e86PHP\u4ee3\u7801\u7684\u7075\u6d3b\u6027\u548c\u8868\u8fbe\u80fd\u529b\u3002<\/p>\n<p>#### \u4e09\u3001\u547d\u540d\u53c2\u6570<\/p>\n<p>PHP 8\u5f15\u5165\u7684\u547d\u540d\u53c2\u6570\u7279\u6027\u5141\u8bb8\u5728\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u901a\u8fc7\u53c2\u6570\u540d\u800c\u975e\u53c2\u6570\u4f4d\u7f6e\u6765\u4f20\u9012\u53c2\u6570\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u4ee3\u7801\u66f4\u6e05\u6670\u3001\u66f4\u6613\u8bfb\uff0c\u540c\u65f6\u4e5f\u51cf\u5c11\u4e86\u56e0\u53c2\u6570\u987a\u5e8f\u9519\u8bef\u5bfc\u81f4\u7684bug\u3002\u547d\u540d\u53c2\u6570\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u5065\u58ee\u6027\uff0c\u662f\u4e00\u4e2a\u957f\u671f\u53d7\u5230\u671f\u5f85\u7684\u7279\u6027\u3002<\/p>\n<p>#### \u56db\u3001\u6784\u9020\u5668\u5c5e\u6027\u63d0\u5347<\/p>\n<p>\u5728\u4e4b\u524d\u7684PHP\u7248\u672c\u4e2d\uff0c\u7c7b\u7684\u6784\u9020\u51fd\u6570\u9700\u8981\u5148\u58f0\u660e\u5c5e\u6027\uff0c\u7136\u540e\u5728\u6784\u9020\u51fd\u6570\u4e2d\u518d\u6b21\u58f0\u660e\u8fd9\u4e9b\u5c5e\u6027\u7684\u503c\u3002PHP 8\u901a\u8fc7\u6784\u9020\u5668\u5c5e\u6027\u63d0\u5347\u7279\u6027\u7b80\u5316\u4e86\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u5141\u8bb8\u5728\u6784\u9020\u51fd\u6570\u4e2d\u76f4\u63a5\u5b9a\u4e49\u5c5e\u6027\u3002\u8fd9\u6837\u4e0d\u4ec5\u51cf\u5c11\u4e86\u4ee3\u7801\u91cf\uff0c\u4e5f\u4f7f\u5f97\u7c7b\u7684\u7ed3\u6784\u66f4\u6e05\u6670\u3002<\/p>\n<p>#### \u4e94\u3001\u5339\u914d\u8868\u8fbe\u5f0f<\/p>\n<p>PHP 8\u5f15\u5165\u4e86\u5339\u914d\u8868\u8fbe\u5f0f\uff08match expression\uff09\uff0c\u8fd9\u662f\u4e00\u4e2a\u6bd4\u73b0\u6709\u7684switch\u8bed\u53e5\u66f4\u5f3a\u5927\u3001\u66f4\u7075\u6d3b\u7684\u7ed3\u6784\u3002\u5b83\u5141\u8bb8\u57fa\u4e8e\u8868\u8fbe\u5f0f\u7684\u503c\u8fdb\u884c\u6761\u4ef6\u5206\u652f\uff0c\u4e14\u76f8\u6bd4switch\uff0cmatch\u8868\u8fbe\u5f0f\u5177\u6709\u4e25\u683c\u7c7b\u578b\u68c0\u67e5\uff0c\u53ef\u4ee5\u51cf\u5c11bug\u7684\u53d1\u751f\u3002<\/p>\n<p>#### \u516d\u3001\u9519\u8bef\u5904\u7406\u7684\u6539\u8fdb<\/p>\n<p>PHP 8\u5728\u9519\u8bef\u5904\u7406\u65b9\u9762\u4e5f\u505a\u4e86\u5927\u91cf\u7684\u6539\u8fdb\uff0c\u5305\u62ec\u5c06\u4e00\u4e9b\u5e38\u89c1\u7684\u8b66\u544a\u548c\u901a\u77e5\u8f6c\u6362\u4e3a\u9519\u8bef\u5f02\u5e38\u3002\u8fd9\u610f\u5473\u7740\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u6355\u83b7\u5e76\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\uff0c\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u5065\u58ee\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<p>#### \u4e03\u3001\u5176\u4ed6\u65b0\u7279\u6027\u548c\u6539\u8fdb<\/p>\n<p>\u9664\u4e86\u4e0a\u8ff0\u4e3b\u8981\u7279\u6027\u5916\uff0cPHP 8\u8fd8\u5f15\u5165\u4e86\u8bb8\u591a\u5176\u4ed6\u7684\u65b0\u7279\u6027\u548c\u6539\u8fdb\uff0c\u5305\u62ec\u5c5e\u6027\u7ec4\u3001\u9759\u6001\u8fd4\u56de\u7c7b\u578b\u3001\u5f31\u6620\u5c04\u3001\u5b57\u7b26\u4e32\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u68c0\u67e5\u51fd\u6570\u7b49\u3002\u8fd9\u4e9b\u6539\u8fdb\u8fdb\u4e00\u6b65\u589e\u5f3a\u4e86PHP\u4f5c\u4e3a\u4e00\u95e8\u73b0\u4ee3\u7f16\u7a0b\u8bed\u8a00\u7684\u5730\u4f4d\uff0c\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u5de5\u5177\u548c\u529f\u80fd\uff0c\u4ee5\u7f16<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u6709\u54ea\u4e9bPHP 8\u7684\u65b0\u529f\u80fd\u548c\u6539\u8fdb\uff1f<\/strong><\/p>\n<p>PHP 8\u5e26\u6765\u4e86\u8bb8\u591a\u65b0\u7279\u6027\u548c\u6539\u8fdb\uff0c\u5176\u4e2d\u5305\u62ecJIT\u7f16\u8bd1\u5668\u3001\u547d\u540d\u53c2\u6570\u3001Match\u8868\u8fbe\u5f0f\u3001\u8054\u5408\u7c7b\u578b\u3001\u5c5e\u6027\u53d8\u91cf\u652f\u6301\u3001\u9759\u6001\u8fd4\u56de\u7c7b\u578b\u3001\u62bd\u8c61\u65b9\u6cd5\u7684\u63a5\u53e3\u9ed8\u8ba4\u5b9e\u73b0\u7b49\u3002\u8fd9\u4e9b\u529f\u80fd\u4f7fPHP\u66f4\u52a0\u5f3a\u5927\u548c\u6613\u4e8e\u4f7f\u7528\uff0c\u6709\u52a9\u4e8e\u63d0\u9ad8\u6027\u80fd\u548c\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p><strong>JIT\u7f16\u8bd1\u5668\u662fPHP 8\u7684\u4e00\u4e2a\u91cd\u8981\u7279\u6027\uff0c\u5b83\u662f\u5982\u4f55\u63d0\u9ad8\u6027\u80fd\u7684\uff1f<\/strong><\/p>\n<p>JIT\u7f16\u8bd1\u5668\uff08\u5373\u65f6\u7f16\u8bd1\u5668\uff09\u53ef\u4ee5\u5c06PHP\u4ee3\u7801\u52a8\u6001\u7f16\u8bd1\u6210\u672c\u673a\u4ee3\u7801\uff0c\u4ee5\u63d0\u9ad8\u6267\u884c\u901f\u5ea6\u3002\u901a\u8fc7JIT\u7f16\u8bd1\u5668\uff0cPHP\u4ee3\u7801\u53ef\u4ee5\u66f4\u5feb\u5730\u6267\u884c\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u90a3\u4e9b\u9700\u8981\u9891\u7e41\u6267\u884c\u7684\u4ee3\u7801\u5757\u6765\u8bf4\uff0c\u6548\u679c\u66f4\u52a0\u663e\u8457\u3002\u8fd9\u4e00\u7279\u6027\u4f7f\u5f97PHP 8\u5728\u6027\u80fd\u65b9\u9762\u6709\u4e86\u660e\u663e\u7684\u63d0\u5347\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u4f53\u9a8c\u3002<\/p>\n<p><strong>Match\u8868\u8fbe\u5f0f\u548cswitch\u8bed\u53e5\u6709\u4ec0\u4e48\u4e0d\u540c\uff1f<\/strong><\/p>\n<p>Match\u8868\u8fbe\u5f0f\u662fPHP 8\u4e2d\u5f15\u5165\u7684\u4e00\u79cd\u65b0\u7684\u8bed\u6cd5\u7ed3\u6784\uff0c\u7528\u4e8e\u6839\u636e\u8868\u8fbe\u5f0f\u7684\u503c\u6765\u6267\u884c\u4e0d\u540c\u7684\u4ee3\u7801\u5757\u3002\u4e0e\u4f20\u7edf\u7684switch\u8bed\u53e5\u76f8\u6bd4\uff0cMatch\u8868\u8fbe\u5f0f\u66f4\u4e3a\u7b80\u6d01\u3001\u6613\u8bfb\uff0c\u4e0d\u9700\u8981\u4f7f\u7528break\u5173\u952e\u5b57\u6765\u7ec8\u6b62\u5bf9\u5e94\u5206\u652f\u7684\u6267\u884c\u3002\u540c\u65f6\uff0cMatch\u8868\u8fbe\u5f0f\u652f\u6301\u66f4\u5e7f\u6cdb\u7684\u6bd4\u8f83\u64cd\u4f5c\uff0c\u5305\u62ec\u7c7b\u578b\u4e25\u683c\u5339\u914d\uff08===\uff09\u7b49\u3002\u8fd9\u4f7f\u5f97Match\u8868\u8fbe\u5f0f\u5728\u7f16\u5199\u6761\u4ef6\u5224\u65ad\u903b\u8f91\u65f6\u66f4\u52a0\u65b9\u4fbf\u548c\u7075\u6d3b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"### PHP 8\u7684\u65b0\u7279\u6027\u6709\u54ea\u4e9b \u5728PHP 8\u7684\u4e16\u754c\u4e2d\uff0cJIT\u7f16\u8bd1\u5668\u3001\u8054\u5408\u7c7b\u578b\u3001\u547d\u540d\u53c2\u6570\u3001\u6784\u9020\u5668\u5c5e\u6027\u63d0\u5347\u3001\u5339\u914d [&hellip;]","protected":false},"author":1,"featured_media":73838,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/73835"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=73835"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/73835\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/73838"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=73835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=73835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=73835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}