PHP 8.0 UPGRADE NOTES1. Backward Incompatible Changes2. New Features3. Changes in SAPI modules4. Deprecated Functionality5. Changed Functions6. New Functions7. New Classes and Interfaces8. Removed Extensions and SAPIs9. Other Changes to Extensions10. New Global Constants11. Changes to INI File Handling12. Windows Support13. Other Changes14. Performance Improvements========================================1. Backward Incompatible Changes========================================- Core:. Methods with the same name as the class are no longer interpreted asconstructors. The __construct() method should be used instead.. Removed ability to call non-static methods statically.. Removed (unset) cast.. Removed track_errors ini directive. This means that $php_errormsg is nolonger available. The error_get_last() function may be used instead.. Removed the ability to define case-insensitive constants. The thirdargument to define() may no longer be true.. Access to undefined constants now always results in an Error exception.Previously, unqualified constant accesses resulted in a warning and wereinterpreted as strings.. Removed ability to specify an autoloader using an __autoload() function.spl_autoload_register() should be used instead.. Removed the $errcontext argument for custom error handlers.. Removed create_function(). Anonymous functions may be used instead.. Removed each(). foreach or ArrayIterator should be used instead.. Removed ability to unbind $this from closures that were created from amethod, using Closure::fromCallable() or ReflectionMethod::getClosure().. Also removed ability to unbind $this from proper closures that contain usesof $this.. Removed ability to use array_key_exists() with objects. Use one of isset()or property_exists() instead.. Any array that has a number n as its first numeric key will use n+1 forits next implicit key. Even if n is negative.RFC: https://wiki.php.net/rfc/negative_array_index. The default error_reporting level is now E_ALL. Previously it excludedE_NOTICE and E_DEPRECATED.. display_startup_errors is now enabled by default.. Using "parent" inside a class that has no parent will now result in afatal compile-time error.. The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR,E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlersthat expect error_reporting to be 0 when @ is used, should be adjusted touse a mask check instead:// Replacefunction my_error_handler($err_no, $err_msg, $filename, $linenum) {if (error_reporting() == 0) {return; // Silenced}// ...}// Withfunction my_error_handler($err_no, $err_msg, $filename, $linenum) {if (!(error_reporting() & $err_no)) {return; // Silenced}// ...}Additionally, care should be taken that error messages are not displayed inproduction environments, which can result in information leaks. Pleaseensure that display_errors=Off is used in conjunction with error logging.. Inheritance errors due to incompatible method signatures (LSP violations)will now always generate a fatal error. Previously a warning was generatedin some cases.RFC: https://wiki.php.net/rfc/lsp_errors. The precedence of the concatenation operator has changed relative tobitshifts and addition as well as subtraction.RFC: https://wiki.php.net/rfc/concatenation_precedence. Arguments with a default-value that resolves to null at run-time will nolonger implicitly mark the argument type as nullable. Either use an explicitnullable type, or an explicit null default value instead.// Replacefunction test(int $arg = CONST_RESOLVING_TO_NULL) {}// Withfunction test(?int $arg = CONST_RESOLVING_TO_NULL) {}// Orfunction test(int $arg = null) {}. A number of warnings have been converted into Error exceptions:* Attempting to write to a property of a non-object. Previously thisimplicitly created an stdClass object for null, false and empty strings.* Attempting to append an element to an array for which the PHP_INT_MAX keyis already used.* Attempting to use an invalid type (array or object) as an array key orstring offset.* Attempting to write to an array index of a scalar value.* Attempting to unpack a non-array/Traversable.A number of notices have been converted into warnings:* Attempting to read an undefined variable.* Attempting to read an undefined property.* Attempting to read a property of a non-object.* Attempting to access an array index of a non-array.* Attempting to convert an array to string.* Attempting to use a resource as an array key.* Attempting to use null, a boolean or a float as a string offset.* Attempting to read an out-of-bounds string offset.RFC: https://wiki.php.net/rfc/engine_warnings. Unexpected characters in source files (such as null bytes outside ofstrings) will now result in a ParseError exception instead of a compilewarning.. Uncaught exceptions now go through "clean shutdown", which means thatdestructors will be called after an uncaught exception.- COM:. Removed the ability to import case-insensitive constants from typelibraries. The second argument to com_load_typelib() may no longer be false;com.autoregister_casesensitive may no longer be disabled; case-insensitivemarkers in com.typelib_file are ignored.- Date:. mktime() and gmmktime() now require at least one argument. time() can beused to get the current timestamp.- dom:. Remove unimplemented classes from ext/dom that had no behavior and containedtest data. These classes have also been removed in the latest version of DOMstandard:* DOMNameList* DomImplementationList* DOMConfiguration* DomError* DomErrorHandler* DOMImplementationSource* DOMLocator* DOMUserDataHandler* DOMTypeInfo- Exif:. Removed read_exif_data(). exif_read_data() should be used instead.- Filter:. The FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED flags for theFILTER_VALIDATE_URL filter have been removed. The scheme and host are (andhave been) always required.. The INPUT_REQUEST and INPUT_SESSION source for filter_input() etc have beenremoved. These were never implemented and their use always generated awarning.- GD:. The GD extension now uses objects as the underlying data structure forimages, rather than resources. These objects are completely opaque, i.e.they don't have any methods.. The deprecated function image2wbmp() has been removed.RFC: https://wiki.php.net/rfc/image2wbmp. The deprecated functions png2wbmp() and jpeg2wbmp() have been removed.RFC: https://wiki.php.net/rfc/deprecate-png-jpeg-2wbmp. The default $mode parameter of imagecropauto() no longer accepts -1.IMG_CROP_DEFAULT should be used instead.- GMP:. gmp_random() has been removed. One of gmp_random_range() orgmp_random_bits() should be used instead.- Intl:. The deprecated constant INTL_IDNA_VARIANT_2003 has been removed.RFC: https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003. The deprecated Normalizer::NONE constant has been removed.- LDAP:. The deprecated function ldap_sort has been removed.- Mbstring:. The mbstring.func_overload directive has been removed. The relatedMB_OVERLOAD_MAIL, MB_OVERLOAD_STRING, and MB_OVERLOAD_REGEX constants havealso been removed. Finally, the "func_overload" and "func_overload_list"entries in mb_get_info() have been removed.. mb_parse_str() can no longer be used without specifying a result array.. A number of deprecated mbregex aliases have been removed. See the followinglist for which functions should be used instead:* mbregex_encoding() -> mb_regex_encoding()* mbereg() -> mb_ereg()* mberegi() -> mb_eregi()* mbereg_replace() -> mb_ereg_replace()* mberegi_replace() -> mb_eregi_replace()* mbsplit() -> mb_split()* mbereg_match() -> mb_ereg_match()* mbereg_search() -> mb_ereg_search()* mbereg_search_pos() -> mb_ereg_search_pos()* mbereg_search_regs() -> mb_ereg_search_regs()* mbereg_search_init() -> mb_ereg_search_init()* mbereg_search_getregs() -> mb_ereg_search_getregs()* mbereg_search_getpos() -> mb_ereg_search_getpos()* mbereg_search_setpos() -> mb_ereg_search_setpos(). The 'e' modifier for mb_ereg_replace() has been removed.mb_ereg_replace_callback() should be used instead.. A non-string pattern argument to mb_ereg_replace() will now be interpretedas a string instead of an ASCII codepoint. The previous behavior may berestored with an explicit call to chr().. The $is_hex parameter, which was not used internally, has been removed frommb_decode_numericentity().. The legacy behaviour of passing the encoding as the third argument instead of an offset for the mb_strrposfunction has been removed, provide an explicit 0 offset with the encoding as the fourth argument.- PCRE:. When passing invalid escape sequences they are no longer interpreted asliterals. This behaviour previously required the X modifier - which isnow ignored.- PDO:. The method PDOStatement::setFetchMode() now accepts the following signature:PDOStatement::setFetchMode($mode, $classname, $params)- PDO_ODBC:. The php.ini directive pdo_odbc.db2_instance_name has been removed- Reflection:. The method signaturesReflectionClass::newInstance($args)ReflectionFunction::invoke($args)ReflectionMethod::invoke($object, $args)have been changed to:ReflectionClass::newInstance(...$args)ReflectionFunction::invoke(...$args)ReflectionMethod::invoke($object, ...$args)Code that must be compatible with both PHP 7 and PHP 8 can use the followingsignatures to be compatible with both versions:ReflectionClass::newInstance($arg = null, ...$args)ReflectionFunction::invoke($arg = null, ...$args)ReflectionMethod::invoke($object, $arg = null, ...$args). The ReflectionType::__toString() method will now return a complete debugrepresentation of the type, and is no longer deprecated. In particular theresult will include a nullability indicator for nullable types. The formatof the return value is not stable and may change between PHP versions.- Socket:. The deprecated AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULESflags for socket_addrinfo_lookup() have been removed.- SPL:. SplFileObject::fgetss() has been removed.. SplHeap::compare($a, $b) now specifies a method signature. Inheritingclasses implementing this method will now have to use a compatiblemethod signature.- Standard:. assert() will no longer evaluate string arguments, instead they will betreated like any other argument. assert($a == $b) should be used instead ofassert('$a == $b'). The assert.quiet_eval ini directive andASSERT_QUIET_EVAL constants have also been removed, as they would no longerhave any effect.. parse_str() can no longer be used without specifying a result array.. fgetss() has been removed.. The string.strip_tags filter has been removed.. The needle argument of strpos(), strrpos(), stripos(), strripos(), strstr(),strchr(), strrchr(), and stristr() will now always be interpreted as astring. Previously non-string needles were interpreted as an ASCII codepoint. An explicit call to chr() can be used to restore the previousbehavior.. The needle argument for strpos(), strrpos(), stripos(), strripos(), strstr() and stristr() can now be empty.. The length argument for substr(), substr_count(), substr_compare(), andiconv_substr() can now be null. Null values will behave as if no lengthargument was provided and will therefore return the remainder of the stringinstead of an empty string.. The length argument for array_splice() can now be null. Null values willbehave identically to omitting the argument, thus removing everything fromthe 'offset' to the end of the array.. The 'salt' option of password_hash() is no longer supported. If the 'salt'option is used a warning is generated, the provided salt is ignored, and agenerated salt is used instead.. The quotemeta() function will now return an empty string if an empty stringwas passed. Previously false was returned.. hebrevc() has been removed.. convert_cyr_string() has been removed.. money_format() has been removed.. ezmlm_hash() has been removed.. get_magic_quotes_gpc() and get_magic_quotes_gpc_runtime() has been removed.. FILTER_SANITIZE_MAGIC_QUOTES has been removed.. Calling implode() with parameters in a reverse order ($pieces, $glue) is nolonger supported.- tidy:. The $use_include_path parameter, which was not used internally, has beenremoved from tidy_repair_string().- XML:. xml_parser_create(_ns) will now return an XmlParser object rather than aresource. Return value checks using is_resource() should be replaced withchecks for `false`. The xml_parser_free() function no longer has an effect,instead the XmlParser instance is automatically destroyed if it is no longerreferenced.- XMLWriter:. The XMLWriter functions now accept and return, respectively, XMLWriterobjects instead of resources.- Zip:. The remove_path option of ZipArchive::addGlob() and ::addPattern() is nowtreated as arbitrary string prefix (for consistency with the add_pathoption), whereas formerly it was treated as directory name. This means thatif no trailing directory separator is given, the following character isno longer stripped from the filename.- Zlib:. gzgetss() has been removed.========================================2. New Features========================================- Core:. Added support for union types.RFC: https://wiki.php.net/rfc/union_types_v2. Added ValueError class.========================================3. Changes in SAPI modules================================================================================4. Deprecated Functionality================================================================================5. Changed Functions================================================================================6. New Functions========================================- SQLite3:. Add SQLite3::setAuthorizer() and respective class constants to set auserland callback that will be used to authorize or not an action on thedatabase.PR: https://github.com/php/php-src/pull/4797- Standard:. Added fdiv() method, which performs a floating-point division underIEEE 754 semantics. Division by zero is considered well-defined andwill return one of Inf, -Inf or NaN.========================================7. New Classes and Interfaces================================================================================8. Removed Extensions and SAPIs================================================================================9. Other Changes to Extensions========================================- GD:. The $num_points parameter of imagepolygon(), imageopenpolygon() andimagefilledpolygon() is now optional, i.e. these functions may be calledwith either 3 or 4 arguments. If the arguments is omitted, it is calculatedas count($points)/2.========================================10. New Global Constants================================================================================11. Changes to INI File Handling================================================================================12. Windows Support================================================================================13. Other Changes================================================================================14. Performance Improvements========================================- array_slice() on an array without gaps will no longer scan the whole array to findthe start offset. This may significantly reduce the runtime of the functionwith large offsets and small lengths.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。