{"id":2812,"date":"2017-10-27T22:13:52","date_gmt":"2017-10-27T14:13:52","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=2812"},"modified":"2017-10-27T22:13:52","modified_gmt":"2017-10-27T14:13:52","slug":"php7%e4%b8%ad%e6%88%91%e4%bb%ac%e5%ba%94%e8%af%a5%e5%ad%a6%e4%b9%a0%e4%bc%9a%e7%94%a8%e7%9a%84%e6%96%b0%e7%89%b9%e6%80%a7","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/chengxujiaoben\/php\/php7%e4%b8%ad%e6%88%91%e4%bb%ac%e5%ba%94%e8%af%a5%e5%ad%a6%e4%b9%a0%e4%bc%9a%e7%94%a8%e7%9a%84%e6%96%b0%e7%89%b9%e6%80%a7\/","title":{"rendered":"PHP7\u4e2d\u6211\u4eec\u5e94\u8be5\u5b66\u4e60\u4f1a\u7528\u7684\u65b0\u7279\u6027"},"content":{"rendered":"<div id=\"postmessage_6564328\" class=\"t_msgfont\">PHP7\u4e8e2015\u5e7411\u6708\u6b63\u5f0f\u53d1\u5e03\uff0c\u672c\u6b21\u66f4\u65b0\u53ef\u8c13\u662fPHP\u7684\u91cd\u8981\u91cc\u7a0b\u7891,\u5b83\u5c06\u5e26\u6765\u663e\u8457\u7684\u6027\u80fd\u6539\u8fdb\u548c\u65b0\u7279\u6027\uff0c\u5e76\u5bf9\u4e4b\u524d\u7248\u672c\u7684\u4e00\u4e9b\u7279\u6027\u8fdb\u884c\u6539\u8fdb\u3002\u672c\u6587\u5c0f\u7f16\u5c06\u548c\u5927\u5bb6\u4e00\u8d77\u6765\u4e86\u89e3\u63a2\u8ba8PHP7\u4e2d\u7684\u65b0\u7279\u6027\u3002<br \/>\n1\uff0e \u6807\u91cf\u7c7b\u578b\u58f0\u660e<br \/>\n\u6211\u4eec\u77e5\u9053PHP\u662f\u4e00\u79cd\u5f31\u7c7b\u578b\u7684\u7f16\u7a0b\u8bed\u8a00,\u56e0\u6b64\u6ca1\u6709\u63d0\u4f9b\u4efb\u4f55\u65b9\u6cd5\u6765\u6307\u5b9a\u8f93\u5165\u53c2\u6570\u548c\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0cPHP7\u7a81\u7834\u4e86\u8fd9\u79cd\u73b0\u72b6\uff0c\u589e\u52a0\u4e86\u5bf9\u6807\u91cf\u7c7b\u578b\uff08int,float,string,bool\uff09\u7684\u58f0\u660e\u652f\u6301\uff0c\u589e\u52a0declare(strict_types=1)\u6307\u4ee4\u58f0\u660e\u662f\u5426\u4e25\u683c\u7c7b\u578b\u6821\u9a8c\uff0c\u6211\u4eec\u6765\u770b\u4e00\u6bb5\u4ee3\u7801\uff1a<br \/>\n(strict_types=) {<br \/>\n$x + $y;<br \/>\n}\u00a0\u00a0add(, );<br \/>\n\u6709\u6548\u7684\u7c7b\u578b\u6709\uff1aclass\/interface name, self, array, callable, bool, float, int and string.<br \/>\n2. ?? \u2014\u2014NULL \u5408\u5e76\u8fd0\u7b97\u7b26<br \/>\nPHP7\u4e2d\u6dfb\u52a0\u4e86NULL\u5408\u5e76\u8fd0\u7b97\u7b26\uff0c\u4e0d\u8981\u5c0f\u770b\u8fd9\u4e2a\u201c??\u201d\uff0c\u6709\u4e86\u5b83\u6211\u4eec\u5c31\u80fd\u5f88\u65b9\u4fbf\u7684\u83b7\u53d6\u4e00\u4e2a\u53c2\u6570\uff0c\u5e76\u80fd\u5728\u5176\u4e3a\u7a7a\u7684\u60c5\u51b5\u4e0b\u63d0\u4f9b\u4e00\u4e2a\u9ed8\u8ba4\u503c\u3002\u5982\u4f55??\u8fd0\u7b97\u7b26\u5de6\u4fa7\u503c\u5b58\u5728\u5e76\u4e14\u4e0d\u4e3aNULL\uff0c\u5219\u8fd4\u56de\u5de6\u4fa7\uff0c\u5426\u5219\u5c06\u8fd4\u56de\u5176\u53f3\u4fa7\u503c\u3002\u6211\u4eec\u8fd8\u662f\u901a\u8fc7\u4e0b\u9762\u4e00\u6bb5\u4ee3\u7801\u6765\u4f53\u9a8c\u4e00\u4e0b??\u8fd0\u7b97\u7b26\u7684\u5f3a\u5927\u5427\u3002<br \/>\n&lt;?php<br \/>\n\/\/ \u83b7\u53d6user\u53c2\u6570\u7684\u503c(\u5982\u679c\u4e3a\u7a7a\uff0c\u5219\u7528&#8217;nobody&#8217;)<br \/>\n\/\/ PHP5\u4e2d\u6211\u4eec\u8fd9\u6837\u6765\u5b9e\u73b0:<br \/>\n$username = isset($_GET[&#8216;user&#8217;]) ? $_GET[&#8216;user&#8217;] : &#8216;nobody&#8217;;<br \/>\n\/\/ PHP7\u4e2d\uff0c\u4f7f\u7528??\u8fd0\u7b97\u7b26\u66f4\u4fbf\u6377:<br \/>\n$username = $_GET[&#8216;user&#8217;] ?? &#8216;nobody&#8217;;<br \/>\n?&gt;<br \/>\n3. \u533f\u540d\u7c7b<br \/>\n\u533f\u540d\u7c7b\u987e\u540d\u601d\u4e49\u6ca1\u6709\u7c7b\u540d\u79f0\uff0c\u5176\u58f0\u660e\u548c\u5b9e\u4f8b\u5316\u662f\u540c\u65f6\u7684\uff0cPHP7 \u652f\u6301\u901a\u8fc7 new class \u6765\u5b9e\u4f8b\u5316\u4e00\u4e2a\u533f\u540d\u7c7b\uff0c\u53ef\u4ee5\u7528\u6765\u66ff\u4ee3\u4e00\u4e9b\u201d\u7528\u540e\u5373\u711a\u201d\u7684\u5b8c\u6574\u7c7b\u5b9a\u4e49\u3002<br \/>\necho ( {<br \/>\n{<br \/>\n;<br \/>\n}<br \/>\n})-&gt;myMethod();<br \/>\n4. \u66f4\u591a Error \u9519\u8bef\u53ef\u4ee5\u8fdb\u884c\u5f02\u5e38\u5904\u7406<br \/>\nPHP7\u4e2d\u66f4\u591a\u7684Error\u53d8\u4e3a\u53ef\u6355\u83b7\u7684Exception\u8fd4\u56de\u7ed9\u5f00\u53d1\u8005\uff0c\u5982\u679c\u4e0d\u8fdb\u884c\u6355\u83b7\u5219\u4e3aError\uff0c\u5982\u679c\u6355\u83b7\u5c31\u53d8\u4e3a\u4e00\u4e2a\u53ef\u5728\u7a0b\u5e8f\u5185\u5904\u7406\u7684Exception\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cError\u4f1a\u76f4\u63a5\u5bfc\u81f4\u7a0b\u5e8f\u4e2d\u65ad\uff0c\u800cPHP7\u5219\u901a\u8fc7try \/ catch\u7a0b\u5e8f\u5757\u6355\u83b7\u5e76\u4e14\u5904\u7406\uff0c\u8ba9\u7a0b\u5e8f\u7ee7\u7eed\u6267\u884c\u4e0b\u53bb\uff0c\u4e3a\u7a0b\u5e8f\u5458\u63d0\u4f9b\u66f4\u7075\u6d3b\u7684\u9009\u62e9\u3002<br \/>\n\u4ee3\u7801\u793a\u4f8b\uff1a<br \/>\nnonExistFunction($arg);<br \/>\n\u8fd9\u65f6\u4e0a\u9762\u7684\u4ee3\u7801\u4f1a\u63d0\u793a\u9519\u8bef\u201cFatal error: Call to a member function method() on a non-object \u201d\uff0c\u5e76\u4e14\u8fd9\u4e2a\u81f4\u547d\u9519\u8bef\u4f1a\u505c\u6b62\u540e\u9762\u4ee3\u7801\u7684\u7ee7\u7eed\u6267\u884c\u3002<br \/>\n\u6240\u4ee5\u5982\u679c\u4f60\u60f3\u7ee7\u7eed\u6267\u884c\u4ee3\u7801\uff0c\u53ef\u4ee5\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u7684\u65b9\u5f0f\u89e3\u51b3\uff1a<br \/>\n{<br \/>\nnonExistFunction($arg);\u00a0\u00a0}\u00a0\u00a0(EngineException $e ) {<br \/>\n;<br \/>\n}<br \/>\n5. \u7ed3\u5408\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08&lt;=&gt; \uff09<br \/>\n\u8fd9\u4e2a\u4e0d\u591a\u89e3\u91ca\uff0c\u6211\u4eec\u76f4\u63a5\u770b\u793a\u4f8b\u4ee3\u7801\uff0c\u901a\u8fc7\u4ee3\u7801\u4f60\u53ef\u4ee5\u5f88\u5bb9\u6613\u4e86\u89e3\u8be5\u8fd0\u7b97\u7b26\u7684\u4f5c\u7528\u3002<br \/>\n{<br \/>\n($a &lt; $b) ?\u00a0\u00a0: (($a &gt; $b) ?\u00a0\u00a0: )<br \/>\n}\u00a0\u00a0{<br \/>\n$a &lt;=&gt; $b;<br \/>\n}<br \/>\n6. \u5b9a\u4e49\u6570\u7ec4\u5e38\u91cf<br \/>\n\u8fc7\u53bb\u6211\u4eec\u5728\u7528define()\u5b9a\u4e49\u5e38\u91cf\u65f6\uff0c\u6570\u636e\u7c7b\u578b\u53ea\u652f\u6301\u6807\u91cf\uff0c\u4f46\u5728PHP7\u4e2d\uff0c\u652f\u6301\u5b9a\u4e49\u6570\u7ec4\u7c7b\u578b\u7684\u5e38\u91cf\u3002<br \/>\ndefine(&#8216;MYCONSTANT&#8217;, array(&#8216;a&#8217;,&#8217;b&#8217;,&#8217;c&#8217;))<br \/>\nPHP7\u65b0\u589e\u7684\u7279\u6027\u8fd8\u6709\u5f88\u591a\uff0c\u4eca\u5929\u6211\u4eec\u5148\u4ecb\u7ecd\u5230\u8fd9\uff0c\u540e\u7eed\u4f1a\u6301\u7eed\u66f4\u65b0\uff0c\u540c\u65f6\u4e5f\u6b22\u8fce\u5e7f\u5927PHPer\u8865\u5145\uff0c\u6211\u4eec\u5171\u540c\u4ea4\u6d41\uff0c\u5171\u540c\u5b66\u4e60\uff0c\u5171\u540c\u8fdb\u6b65\u3002<\/div>\n<div id=\"post_rate_div_6564328\"><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP7\u4e8e2015\u5e7411\u6708\u6b63\u5f0f\u53d1\u5e03\uff0c\u672c\u6b21\u66f4\u65b0\u53ef\u8c13\u662fPHP\u7684\u91cd\u8981\u91cc\u7a0b\u7891,\u5b83\u5c06\u5e26\u6765\u663e\u8457\u7684\u6027\u80fd\u6539\u8fdb\u548c\u65b0\u7279\u6027\uff0c\u5e76\u5bf9\u4e4b\u524d &#8230; <a title=\"PHP7\u4e2d\u6211\u4eec\u5e94\u8be5\u5b66\u4e60\u4f1a\u7528\u7684\u65b0\u7279\u6027\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/chengxujiaoben\/php\/php7%e4%b8%ad%e6%88%91%e4%bb%ac%e5%ba%94%e8%af%a5%e5%ad%a6%e4%b9%a0%e4%bc%9a%e7%94%a8%e7%9a%84%e6%96%b0%e7%89%b9%e6%80%a7\/\" aria-label=\"\u9605\u8bfb PHP7\u4e2d\u6211\u4eec\u5e94\u8be5\u5b66\u4e60\u4f1a\u7528\u7684\u65b0\u7279\u6027\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[369],"class_list":["post-2812","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=2812"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2812\/revisions"}],"predecessor-version":[{"id":2813,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/2812\/revisions\/2813"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=2812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=2812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=2812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}