rfc:deprecations_php_8_0
This is an old revision of the document!
PHP RFC: Deprecations for PHP 8.1
- Date: 2019-07-23
- Author: Nikita Popov nikic@php.net, George Peter Banyard girgias@php.net
- Status: Under Discussion
Introduction
The RFC proposes to deprecate the listed functionality in PHP 8.1 and remove it in PHP 9.
The following list provides a short overview of the functionality targeted for deprecation, while more detailed explanation is provided in the Proposal section:
date_sunrise()anddate_sunset()key(),current(),next(),prev(), andreset()on objectsmb_check_encoding()without argumentget_class(),get_parent_class()andget_called_class()without argumentFILE_BINARYandFILE_TEXTconstantstfopen mode- Passing bool for
$amountOrUpOrDownargument ofIntlCalendar::roll() - Accessing static members on traits
strftime()andgmtstrftime()- Passing a method name as the first parameter to
ReflectionMethod's constructor mhash*()function familyDatePeriod::construct()===== Proposal ===== Each feature proposed for deprecation is voted separately and requires a 2/3 majority. All votes refer to deprecation in PHP 8.1 and removal in PHP 9.0. ==== date_sunrise() and date_sunset() ==== These two functions have the signature: <PHP> function date_sunset( int $timestamp, int $format = SUNFUNCS_RET_STRING, float $latitude = ini_get(“date.default_latitude”), float $longitude = ini_get(“date.default_longitude”), float $zenith = ini_get(“date.sunset_zenith”), float $gmt_offset = 0 ): mixed; </PHP> This function depends on ini settings that specify the “default” latitude and longitude, a concept that makes very little sense. Additionally it requires familiarity with appropriate zenith values to use for different purposes.date_sunset()anddate_sunrise()have since been superseded bydate_sun_info(): <PHP> function date_sun_info(int $time, float $latitude, float $longitude): array; </PHP> This function does not use “default” latitude and longitude, and returns an associative array of multiple different definitions of the sunrise/sunset concept. The proposal is to deprecatedate_sunset()anddate_sunrise()in favor ofdate_sun_info(). The ini settingsdate.default_latitude,date.default_longitudeanddate.sunset_zenithare marked as deprecated in the documentation. In the next major version, both the functions and the ini settings will be removed. This was initially discussed in: https://github.com/php/php-src/pull/4423. ==== key(), current(), next(), prev(), reset() on objects ==== Thekey()family of functions, which are used to manipulate the internal array pointer, also accept objects. In this case they work on the mangled property table. That is, usingkey()and friends on an object is essentially the same as using them onget_mangled_object_vars($object). This catches many people off guard, because they expectkey()etc. to integrate with the iterator interface. That is, if the passed object implementsIteratorthenkey($object)should perform an$object->key()call. The water here have been further muddied byArrayObject, which prior to PHP 7.4 was the only object wherekey()etc. did effectively integrate with the iterator interface. There are principally two ways to resolve this: The first is to deprecate the use ofkey()etc on objects, and instead require people to perform an explicit(array)cast orget_mangled_object_vars()call beforehand. The other is to actually make these functions integrate with iterators. The issue I see with the latter is that we would only be able to support theIteratorinterface proper, but not generalTraversables: For theseIteratorAggregate::getIterator(), or the internalget_iterator()handler need to be called once at the start, which is not possible through the array iteration interface, as it consists of multiple independent functions. Additionally, theprev()function cannot be implemented for iterators. As such, the proposal is to deprecate key(), current(), next(), prev() and reset() on objects. The suggested replacement is to cast the object to array first, or callget_mangled_object_vars(), depending on what the intention is. ==== mb_check_encoding() without argument ==== Themb_check_encoding()usually accepts a string and an encoding, but can also be called without arguments. The documentation says: > If it is omitted, this function checks all the input from the beginning of the request. The implementation says: <code> /*MBSTRG(illegalchars): Actually check all inputs, except $_FILES file content. */ if (MBSTRG(illegalchars) == 0) { RETURN_TRUE; } RETURN_FALSE; </code> This FIXME does not induce a sense of confidence in this function... Further research shows that the documentation is correct, in that any encoding checking or conversion functionality invoked during a request will increment
. As such,mb_check_encoding()tells you whether any illegal encoding has been encountered at any point. My best guess is that this was intended to be used in conjunction with theencoding_translationfeature, which “treats” incoming SAPI data. Overall this functionality is confusing, and the implementation is unfinished or broken. There are no calls tomb_check_encoding()without argument in popular composer packages. The proposal is to deprecate callingmb_check_encoding()without arguments. ==== get_class(), get_parent_class() and get_called_class() without argument ==== In PHP 7.2, passing null to ''get_class()'' was forbidden, because this behavior was very bug prone. However, the ability to callget_class()without argument was retained. In that caseget_class()is approximately the same asself::class.get_parent_class()exhibits the same behavior. The proposal is to deprecate argument-lessget_class(),get_parent_class()andget_called_class()in favor of the dedicatedself::class,parent::classandstatic::classsyntax, which was introduced in PHP 5.5. (get_called_class()only has an argument-less form, so it would be deprecated entirely.) As a caveat, ifget_parent_class()is used to check whether the class has a parent, it is necessary to useget_parent_class(self::class)instead, becauseparent::classwill generate an error if used inside a class without parent. ==== FILE_BINARY and FILE_TEXT constants ==== These were introduced in PHP 5.2.7 for forward compatibility with PHP 6, but don't have any effect. These constants are especially confusing becausefopen()supportsb(binary) andt(text) modes, which do have an effect, but a completely unrelated one. The proposal is to deprecate theFILE_BINARYandFILE_TEXTconstants. This was pointed out in: https://github.com/php/php-src/pull/5556 ==== “t” fopen mode ==== Next to the standard modes, fopen also acceptstandbmodes, which are only meaningful on Windows. Whenbis used (which is the default), the file is treated as usual. Iftis specified, automatic conversion between LF and CRLF line endings is performed. The documentation says: > Again, for portability, it is also strongly recommended that you re-write code that uses or relies upon the 't' mode so that it uses the correct line endings and 'b' mode instead. The proposal is to deprecate the use oftmode in fopen(). Explicitly specifying thebmode remains supported. There is a complication here: Whilefopen()itself defaults to binary mode, some other functions likeproc_open()on pipe descriptors still default to text mode. The default for these functions should be swapped for PHP 8, independently of this deprecation proposal. ==== Passing bool for $amountOrUpOrDown argument of IntlCalendar::roll() ==== <php>IntlCalendar::roll()</php> accepts an integer which specifies how much to add to a given field. The integer can be negative to subtract. However, it also accepts a boolean argument, in which casetrueis interpreted as1andfalseis interpreted as-1. This does not appear to be actually useful for anything, makes for a confusing function signature, and violates PHP's usual type coercion rules. The proposal is to deprecate passing a boolean to this method argument. ==== Accessing static members on traits ==== Currently, it is possible to directly access static trait members, rather than accessing them on the class using the trait: <PHP> trait T { public static $foo; } class C { use T; } var_dump(T::$foo); Allowed. </PHP> This is conceptually wrong, and causes various complications. For example, the meaning ofselfis ill-defined (which normally refers to the using class, not the trait), the behavior of static variables in methods may change depending on whether a trait method has been called prior to being used, and opcache preloading requires constant initializers in traits to be fully resolved (as they may be used directly). There is a somewhat dated analysis of projects using this “feature” at https://github.com/php/php-src/pull/4829#issuecomment-542224541. The proposal is to deprecate the ability to access static properties and static methods directly on traits. ==== strftime() and gmstrftime() ==== ==== strptime() ==== ==== Passing a method name as the first parameter to ReflectionMethod::construct() ==== AReflectionMethod::fromMethodName()method should be added as a replacement. ==== mhash*() function family ====mhash*()functions were integrated into ext/hash in PHP 5.3 as a compatibility layer for ext/mhash (which has been removed in PHP 7.0), but they are hardly ever used, and very ill-behaved (primarilymhash()). ==== DatePeriod::construct() ==== This is a heavily overloaded function (it has 3 signatures) which should be deprecated in favour of 3 factory methods. ===== Backward Incompatible Changes ===== For PHP 8.1 additional deprecation notices will appear. For PHP 9.0 the previously deprecated functionality will no longer be available. ===== Removed from this proposal ===== The following entries were originally added to this proposal and then dropped. ==== DateTimeInterface::ISO8601 ==== The documentation says: > Note: This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead. There's a number of bug reports related to this. From what I understand, the core problem here is not that the ISO8601 format is wrong, it's just one of multiple legal ISO-8601 formats. As DateTime formats always refer to a specific format, not a set of multiple possible ones, there doesn't seem to be anything actionable here. ==== get_browser() function ==== This was originally included on the rationale thatget_browser()is much slower than userland browscap implementations. However, this is no longer the case since a PHP 7.0 patch release, see https://github.com/php/php-src/pull/2242.
rfc/deprecations_php_8_0.1600529716.txt.gz · Last modified: (external edit)