rfc:deprecations_php_7_1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:deprecations_php_7_1 [2016/03/27 11:36] nikicrfc:deprecations_php_7_1 [2016/10/29 16:21] nikic
Line 1: Line 1:
-====== PHP RFC: Deprecations for PHP 7.======+====== PHP RFC: Deprecations for PHP 7.======
   * Date: 2015-12-28   * Date: 2015-12-28
   * Author: Nikita Popov <nikic@php.net>   * Author: Nikita Popov <nikic@php.net>
Line 7: Line 7:
 ===== Introduction ===== ===== Introduction =====
  
-This is a draft RFC for multiple deprecations targeting PHP 7.1. The RFC proposes to deprecate the listed functionality in PHP 7.and remove it no later than in PHP 8.0.+This is a draft RFC for multiple deprecations targeting PHP 7.2. The RFC proposes to deprecate the listed functionality in PHP 7.and remove it no later than in PHP 8.0.
  
 The following list provides a short overview of the functionality targeted for deprecation, while more detailed explanation is provided in the Proposal section: The following list provides a short overview of the functionality targeted for deprecation, while more detailed explanation is provided in the Proposal section:
Line 14: Line 14:
   * ''$php_errormsg''   * ''$php_errormsg''
   * ''create_function()''   * ''create_function()''
-  * ''rand()'', ''srand()'' and ''getrandmax()'' 
   * ''mbstring.func_overload''   * ''mbstring.func_overload''
   * ''(unset)'' cast   * ''(unset)'' cast
 +  * ''parse_str()'' without second argument
 +  * ''gmp_random()''
 +  * ''(binary)'' cast and ''%%b""%%'' literals
 +  * ''each()''
 +  * ''assert()'' with string argument
 +  * ''$errcontext'' argument of error handler
  
 ===== Proposal ===== ===== Proposal =====
Line 41: Line 46:
  
 Proposed action: Mark the function as deprecated, thus issuing a deprecation notice on every call. Proposed action: Mark the function as deprecated, thus issuing a deprecation notice on every call.
- 
-==== rand(), srand() and getrandmax() ==== 
- 
-The [[http://php.net/rand|rand()]] function exposes the libc random number generator to PHP. The output and quality of this random number generator is system dependent. Notably, on Windows rand() can only generate at most 32767 unique values for any value range (if the value range includes more than 32767 numbers, some numbers will never be returned). Furthermore Windows uses a very low quality linear congruential generator with bad statistical properties (it's so bad you can see the non-uniformity with the naked eye). 
- 
-As alternative, PHP provides [[http://php.net/mt_rand|mt_rand()]], which is based on the 32-bit MT19937 algorithm. While not ideal (it generates at most 2147483647 unique values, even on 64-bit platforms), mt_rand() is strictly superior to rand() and does not have a platform dependence. It should always be preferred over rand(). 
- 
-The corresponding seeding function is [[http://php.net/srand|srand()]] and [[http://php.net/getrandmax|getrandmax()]] returns the maximum number returned by the underlying generator. If rand() is deprecated, these should be deprecated as well. 
- 
-Proposed action: Mark all three functions as deprecated, thus issuing a deprecation notice on every call. 
- 
-Alternative action: Alias rand() etc. to the corresponding mt_*() functions. We may want to do some other changes do our non-crypto PRNG functionality at the same time, see http://markmail.org/message/gxjpvmvguhpni5zu. 
  
 ==== mbstring.func_overload ==== ==== mbstring.func_overload ====
Line 71: Line 64:
  
 Proposed action: Throw a deprecation notice if an ''(unset)'' cast is encountered by the compiler. No deprecation notice is thrown from the lexer or parser themselves (so that ''token_get_all'' continues working as is). Proposed action: Throw a deprecation notice if an ''(unset)'' cast is encountered by the compiler. No deprecation notice is thrown from the lexer or parser themselves (so that ''token_get_all'' continues working as is).
 +
 +==== parse_str() without second argument ====
 +
 +The [[http://php.net/parse_str|parse_str()]] function is used to parse a query string either into an array if the second argument is used, or into the local symbol table if it is not used.
 +
 +The second behavior is a remnant from the dark age of register_globals. It suffers from many of the same problems and presents a major security hazard if used on user-provided data.
 +
 +Proposed action: Throw a deprecation notice if the second argument of ''parse_str()'' is not used.
 +
 +==== gmp_random() ====
 +
 +The [[http://php.net/gmp_random|gmp_random()]] function returns a random GMP number between ''0'' and ''%%2**($n*BITS_PER_LIMB)-1%%'', where ''$n'' is the function argument and ''BITS_PER_LIMB'' is a platform-specific parameter of the GMP/MPIR implementation that is **not exposed to userland**. As such, use of this function requires guessing the limb size and will likely have a platform dependence.
 +
 +To remedy this PHP 5.6 introduced the [[http://php.net/manual/en/function.gmp-random-bits.php|gmp_random_bits()]] and [[http://php.net/manual/en/function.gmp-random-range.php|gmp_random_range()]] functions, which allow precise control of the used random number range. These functions should always be preferred over ''gmp_random()''.
 +
 +Proposed action: Mark the function as deprecated, thus issuing a deprecation notice on every call.
 +
 +==== (binary) cast and b"" literals ====
 +
 +The binary cast and binary string literals were originally introduced as forward-compatibility features for PHP 6. Currently they behave identically to ordinary (string) casts and ordinary string literals. Given that PHP 6 has been dead for years and it is unlikely that it will be resurrected in the same form, it is time to remove these forward-compatibility tokens.
 +
 +Proposed action: Throw a compile-time deprecation whenever binary casts or binary string literals are used.
 +
 +==== each() ====
 +
 +The ''each()'' function can be used to iterate over an array, similarly to using ''foreach''. On each call, it returns an array with the current key and value and advances the internal array pointer to the next position. The typical usage, as presented in the manual, is as follows:
 +
 +<code php>
 +reset($array);
 +while (list($key, $val) = each($array)) {
 +    echo "$key => $val\n";
 +}
 +</code>
 +
 +The ''each()'' function is inferior to ''foreach'' in pretty much every imaginable way, including being more than 10 times slower. The continued existence of this function poses a problem for certain language changes. For example the [[https://wiki.php.net/rfc/notice-for-non-valid-array-container]] RFC had to exclude ''list()'', because the typical usage of ''each'' relies on the fact that you can access array offsets on ''false'' without a warning.
 +
 +Proposed action: As ''each'' is typically called within loops, throwing a deprecation warning for every call is likely not advisable. Instead, throw a deprecation warning on the first call for any given request.
 +
 +==== assert() with string argument ====
 +
 +The ''assert()'' function has two modes of operation: If it is passed something other than a string, it will assert that the value is truthy. If a string is passed, it will be run through ''eval()'' and assert will check that the result of the ''eval()'' is truthy.
 +
 +The reason for this behavior is that prior to PHP 7 this was the only way to prevent the assertion expression from evaluating. As of PHP 7, the ''zend.assertions'' ini option can be used to avoid evaluation of assertion expressions. As such, there is no longer a need for supporting implicitly evaluated string arguments.
 +
 +This behavior of ''assert()'' makes it easy to introduce subtle remote code execution vulnerabilities. Using ''assert($value)'' to check if a value is truthy opens an RCE vulnerability if there is any chance for ''$value'' to be a string.
 +
 +Proposed action: Throw a deprecation notice if ''assert()'' is used with a string argument.
 +
 +==== $errcontext argument of error handler ====
 +
 +Error handlers set with ''set_error_handler()'' are passed an ''$errcontext'' as the last argument. This argument is an array containing all local variables at the point the error was generated.
 +
 +This functionality is problematic for optimization, because the ''$errcontext'' can be used to modify all references and objects in the current scope. As far as I am aware, this functionality is barely used and the trade-off here is not worthwhile. If people wish to inspect the variable-state at the point of an error, they should use a proper debugger.
 +
 +Proposed action: Throw deprecation notice if error handler has five or more arguments. Otherwise, do not pass the ''$errcontext''. This prevents circumvention with ''func_get_args()''.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 88: Line 136:
 The following list contains various suggested deprecations that may or may not be included in this RFC (TODO section). The following list contains various suggested deprecations that may or may not be included in this RFC (TODO section).
  
-  * The ''(binary)'' cast and ''%%b""%%'' string syntax. Those were added for forward compatibility with PHP 6, which has been discontinued. 
   * The ''%%"${varName}"%%'', ''%%"${varName['offset']}"%%'' and ''%%"${expr}"%%'' alternative string interpolation syntaxes. These can be replaced by the more obvious and consistent ''%%"{$varName}"%%'', ''%%"{$varName['offset']}"%%'' and ''%%"{${expr}}"%%''. (Maybe leave the latter? That one is a bit awkward.)   * The ''%%"${varName}"%%'', ''%%"${varName['offset']}"%%'' and ''%%"${expr}"%%'' alternative string interpolation syntaxes. These can be replaced by the more obvious and consistent ''%%"{$varName}"%%'', ''%%"{$varName['offset']}"%%'' and ''%%"{${expr}}"%%''. (Maybe leave the latter? That one is a bit awkward.)
   * The alternative parameter order for ''implode()''. Standard order is string, array, but array, string is also allowed for historic reasons.   * The alternative parameter order for ''implode()''. Standard order is string, array, but array, string is also allowed for historic reasons.
   * ''fputcsv'' etc. have been suggested, because they don't conform to the CSV standard. I think it's better to improve the implementation instead.   * ''fputcsv'' etc. have been suggested, because they don't conform to the CSV standard. I think it's better to improve the implementation instead.
   * ''convert_cyr_string'', as the same can be done with ''mb_convert_encoding'' or ''iconv''.   * ''convert_cyr_string'', as the same can be done with ''mb_convert_encoding'' or ''iconv''.
-  * Calling ''parse_str'' without the second parameter. This will put the result into the local symbol table. 
   * ''get_magic_quotes_gpc'', as it's pretty useless by now.   * ''get_magic_quotes_gpc'', as it's pretty useless by now.
   * ''allow_url_include'' ini option.   * ''allow_url_include'' ini option.
Line 99: Line 145:
   * ''sizeof'', which is an alias of ''count''.   * ''sizeof'', which is an alias of ''count''.
   * Second argument to ''spl_autoload''.   * Second argument to ''spl_autoload''.
-  * ''gmp_random'', which is obsoleted by ''gmp_random_bits'' and ''gmp_random_range''.+  * The ticks mechanism, which is obsoleted by async signal handling.
  
 ===== Rejected deprecations ===== ===== Rejected deprecations =====
rfc/deprecations_php_7_1.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1