{"id":526,"date":"2021-04-04T12:42:35","date_gmt":"2021-04-04T04:42:35","guid":{"rendered":"https:\/\/www.orztip.com\/?p=526&#038;article_title="},"modified":"2021-04-04T13:23:33","modified_gmt":"2021-04-04T05:23:33","slug":"php-8-compatibility","status":"publish","type":"post","link":"https:\/\/www.orztip.com\/?p=526&article_title=php-8-compatibility","title":{"rendered":"PHP 8.0\u517c\u5bb9\u6027\u6ce8\u610f\u4e8b\u9879"},"content":{"rendered":"\n<p><strong>\u4e00\u3001\u524d\u8a00<\/strong><\/p>\n\n\n\n<p>\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u9488\u5bf9\u4ecePHP 7.0\u6216\u66f4\u65e9\u7248\u672c\u8de8\u5927\u7248\u672c\u5347\u7ea7\u5230PHP 8.0\u7684\u5f00\u53d1\u8005\u3002<\/p>\n\n\n\n<p>\u5728\u6d4f\u89c8\u672c\u6587\u4e4b\u524d\uff0c\u5efa\u8bae\u9605\u8bfb\u4ee5\u4e0b\u94fe\u63a5\uff1a<\/p>\n\n\n\n<p>\uff08A\uff09\u5b98\u65b9\u7684PHP 8.0\u53d1\u5e03\u4ecb\u7ecd\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.php.net\/releases\/8.0\/en.php\" target=\"_blank\">https:\/\/www.php.net\/releases\/8.0\/en.php<\/a><\/p>\n\n\n\n<p>\uff08B\uff09\u5b89\u5168\u7814\u7a76\u8005phith0n\u53d1\u5e03\u7684\u6587\u7ae0\u300a\u6709\u5b89\u5168\u7814\u7a76\u8005\u6df7\u5165\u4e86PHP 8.0\u5f00\u53d1\u7ec4\uff01\u300b\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/mp.weixin.qq.com\/s\/0HSAPYY2PjbwEN3MhI4SkA\" target=\"_blank\">https:\/\/mp.weixin.qq.com\/s\/0HSAPYY2PjbwEN3MhI4SkA<\/a><\/p>\n\n\n\n<p>\uff08C\uff09\u300a\u4ece PHP 7.4.x \u79fb\u690d\u5230 PHP 8.0.x\u300b\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.php.net\/manual\/zh\/migration80.php\" target=\"_blank\">https:\/\/www.php.net\/manual\/zh\/migration80.php<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"521\" src=\"https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8-1024x521.png\" alt=\"\" class=\"wp-image-537\" srcset=\"https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8-1024x521.png 1024w, https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8-300x153.png 300w, https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8-150x76.png 150w, https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8-768x391.png 768w, https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8-1536x782.png 1536w, https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8-1568x798.png 1568w, https:\/\/www.orztip.com\/mattach_upload\/2021\/04\/php-8.png 1799w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u4e8c\u3001\u8bed\u6cd5\u5f15\u5165\u548c\u53d8\u66f4<\/strong><\/p>\n\n\n\n<p><strong>1\u3001\u4e0d\u518d\u652f\u6301\u5927\u62ec\u53f7\u7684\u6570\u7ec4\u5199\u6cd5\uff08PHP 7.4\u5f15\u5165\uff09<\/strong><\/p>\n\n\n\n<p>\u4ee5\u5f80\u6211\u4eec\u4f1a\u4f7f\u7528\u5927\u62ec\u53f7\u6765\u83b7\u53d6\u5b57\u7b26\u4e32\u67d0\u4e00\u4e2a\u4f4d\u7f6e\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$a = \"abfdcccc\";\n$b = $a{0};<\/code><\/pre>\n\n\n\n<p>\u4ecePHP 7.4\u5f00\u59cb\uff0c\u8be5\u5199\u6cd5\u5c06\u4e0d\u88ab\u652f\u6301\uff0c\u4f1a\u62a5E_COMPILE_ERROR<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;E_COMPILE_ERROR]&#91;Error Code 64] Array and string offset access syntax with curly braces is no longer supported<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u4e09\u3001\u7c7b\u5f15\u5165\u548c\u53d8\u66f4<\/strong><\/p>\n\n\n\n<p><strong>1\u3001Throwable\u63a5\u53e3\u5f15\u5165\uff08PHP 7.0\u5f15\u5165\uff09<\/strong><\/p>\n\n\n\n<p>\u4ecePHP 7.0\u5f00\u59cb\uff0c\u5b98\u65b9\u5f15\u5165Throwable\u63a5\u53e3\u3002\u73b0\u5728Exception\u7c7b\u548cError\u7c7b\u5747\u662fThrowable\u63a5\u53e3\u7684\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f7f\u7528\u4e86set_exception_handler\u63a5\u6536\u9ed8\u8ba4\u5f02\u5e38\u5904\u7406\u65f6\uff0c\u8bf7\u5728PHP 7.0\u68c0\u67e5\u662f\u5426\u5141\u8bb8\u5b9e\u73b0\u4e86Throwable\u63a5\u53e3\u7684\u5b9e\u4f8b\u4f20\u9012\u3002\u5982\u679c\u53ea\u652f\u6301\u4f20\u9012Exception\u5b9e\u4f8b\uff0c\u5219\u5728PHP 7.0\u5f00\u59cb\u4f1a\u5b58\u5728\u95ee\u9898\uff0c\u56e0\u4e3a\u6709\u53ef\u80fd\u4f1a\u4f20\u9012\u65b0\u589e\u7684Error\u5b9e\u4f8b\u3002\u8be6\u89c1\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.php.net\/manual\/en\/function.set-exception-handler.php\" target=\"_blank\">https:\/\/www.php.net\/manual\/en\/function.set-exception-handler.php<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>2\u3001Error\u7c7b\u5f15\u5165\uff08PHP 7.0\u5f15\u5165\uff0c<strong>PHP 7.x\u5f3a\u5316<\/strong><\/strong>\uff0c<strong>PHP 8.0\u5f3a\u5316\uff09<\/strong><\/p>\n\n\n\n<p>\u4ecePHP 7.0\u5f00\u59cb\uff0c\u5b98\u65b9\u5f15\u5165Error\u7c7b\uff0c\u5373\u6240\u6709PHP\u5185\u90e8\u9519\u8bef\u7c7b\u7684\u57fa\u7c7b\u3002\u53c2\u89c1\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.php.net\/manual\/en\/class.error.php\" target=\"_blank\">https:\/\/www.php.net\/manual\/en\/class.error.php<\/a><\/p>\n\n\n\n<p>\u540e\u7eed\u7684PHP 7.x\u7248\u672c\u4e2d\uff0c\u90e8\u5206\u5185\u7f6e\u6269\u5c55\u628a\u539f\u6765\u7684\u8f93\u51fawarning\u8fc1\u79fb\u5230\u629b\u51faError\u7c7b\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<p>\uff08A\uff09ext\/BCMath\u9519\u8bef\u884c\u4e3a\u53d8\u66f4\uff08PHP7.3\u5f15\u5165\uff09\uff1a\u201cBCMath Arbitrary Precision Mathematics: All warnings thrown by BCMath functions\u00a0are now using PHP&#8217;s error handling. Formerly some warnings have directly been written to stderr.\u201d<\/p>\n\n\n\n<p>\u5230\u4e86PHP 8.0\uff0c\u5b98\u65b9\u8fdb\u4e00\u6b65\u5f3a\u5316\u4e86\u8be5\u7c7b\u4f7f\u7528\u8303\u7574\uff1a\u4f7f\u7528PHP\u51fd\u6570\u65f6\uff0c\u5982\u679c\u51fa\u73b0\u53c2\u6570\u9a8c\u8bc1\u9519\u8bef\uff0c\u73b0\u5728\u4f1a\u629b\u51faError\u7c7b\u800c\u4e0d\u662f\u8f93\u51fawarning\u3002\u56e0\u6b64\uff0c\u9700\u8981\u7559\u610f\u5982\u4f55\u5904\u7406\u66f4\u591a\u7684\u5f02\u5e38\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Consistent type errors for internal functions: Most of the internal functions now throw an Error exception if the validation of the parameters fails.<\/p><\/blockquote>\n\n\n\n<p>PHP 7\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>strlen(&#91;]); \/\/ Warning: strlen() expects parameter 1 to be string, array given\n\narray_chunk(&#91;], -1); \/\/ Warning: array_chunk(): Size parameter expected to be greater than 0<\/code><\/pre>\n\n\n\n<p>PHP 8\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>strlen(&#91;]); \/\/ TypeError: strlen(): Argument #1 ($str) must be of type string, array given\n\narray_chunk(&#91;], -1); \/\/ ValueError: array_chunk(): Argument #2 ($length) must be greater than 0<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u56db\u3001\u6269\u5c55\u90e8\u5206<\/strong><\/p>\n\n\n\n<p><strong>1\u3001ext\/mcrypt\u6269\u5c55\u4e0d\u518d\u5185\u7f6e\uff08PHP 7.1\u5e9f\u5f03\uff0cPHP 7.2\u79fb\u9664\uff09<\/strong><\/p>\n\n\n\n<p>\u4ecePHP 7.1\u5f00\u59cb\uff0c\u5185\u7f6e\u7684mcrypt\u6269\u5c55\u88ab\u6807\u8bb0\u4e3a\u5e9f\u5f03\uff1bPHP 7.2\u5f00\u59cb\uff0cmcrypt\u6269\u5c55\u88ab\u4ece\u5185\u7f6e\u5e93\u79fb\u9664\u3002<\/p>\n\n\n\n<p>\u5efa\u8bae\u76f8\u5173\u51fd\u6570\u6539\u7528openssl\u6269\u5c55\u5b9e\u73b0\uff0c\u548c\u5176\u5b83\u7f16\u7a0b\u8bed\u8a00\u5bf9\u63a5\u8d77\u6765\u76f8\u5bf9\u66f4\u901a\u7528\u3002<\/p>\n\n\n\n<p>\u8be6\u7ec6\u89c1\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/www.php.net\/manual\/en\/intro.mcrypt.php\">https:\/\/www.php.net\/manual\/en\/intro.mcrypt.php<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.php.net\/manual\/en\/migration71.deprecated.php\">https:\/\/www.php.net\/manual\/en\/migration71.deprecated.php<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>2\u3001ext\/xmlrpc\u6269\u5c55\u4e0d\u518d\u5185\u7f6e\uff08PHP 8.0\u79fb\u9664\uff09<\/strong><\/p>\n\n\n\n<p>\u4ecePHP 8.0\u5f00\u59cb\uff0c\u5185\u7f6e\u7684xmlrpc\u6269\u5c55\u88ab\u79fb\u9664\u3002<\/p>\n\n\n\n<p>\u5982\u6709\u9700\u8981\uff0c\u8bf7\u81ea\u884c\u4ecePECL\u5e93\u4e0b\u8f7d\u5e76\u7f16\u8bd1\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/pecl.php.net\/package\/xmlrpc\" target=\"_blank\">https:\/\/pecl.php.net\/package\/xmlrpc<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>3\u3001ext\/sodium\u5f15\u5165\uff08PHP 7.2\u5f15\u5165\uff09<\/strong><\/p>\n\n\n\n<p>\u4ecePHP 7.2\u5f00\u59cb\uff0c\u5b98\u65b9\u5f15\u5165sodium\u6269\u5c55\u3002\u8be5\u6269\u5c55\u4f9d\u8d56libsodium\u5e93\u3002<\/p>\n\n\n\n<p>sodium\u6269\u5c55\u53ef\u4ee5\u66ff\u4ee3mcrypt\u6269\u5c55\u7684\u529f\u80fd\uff0c\u4e5f\u80fd\u66ff\u4ee3openssl\u6269\u5c55\u4e2d\u7684\u90e8\u5206\u52a0\u89e3\u5bc6\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u4f46\u7b14\u8005\u5efa\u8bae\uff0c\u5982\u679c\u6d89\u53ca\u548c\u5176\u5b83\u7cfb\u7edf\u6216\u7f16\u7a0b\u8bed\u8a00\u7684\u5bf9\u63a5\uff0c\u4f18\u5148\u4f7f\u7528openssl\u6269\u5c55\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/www.php.net\/manual\/en\/book.sodium.php\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.php.net\/manual\/en\/book.sodium.php<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u524d\u8a00 \u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u9488\u5bf9\u4ecePHP 7.0\u6216\u66f4\u65e9\u7248\u672c\u8de8\u5927\u7248\u672c\u5347\u7ea7\u5230PHP 8.0\u7684\u5f00\u53d1\u8005\u3002 \u5728\u6d4f\u89c8\u672c\u6587\u4e4b\u524d\uff0c\u5efa&hellip; <a class=\"more-link\" href=\"https:\/\/www.orztip.com\/?p=526&#038;article_title=php-8-compatibility\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">PHP 8.0\u517c\u5bb9\u6027\u6ce8\u610f\u4e8b\u9879<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":537,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.orztip.com\/index.php?rest_route=\/wp\/v2\/posts\/526"}],"collection":[{"href":"https:\/\/www.orztip.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orztip.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orztip.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orztip.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=526"}],"version-history":[{"count":10,"href":"https:\/\/www.orztip.com\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":538,"href":"https:\/\/www.orztip.com\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions\/538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.orztip.com\/index.php?rest_route=\/wp\/v2\/media\/537"}],"wp:attachment":[{"href":"https:\/\/www.orztip.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orztip.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orztip.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}