PHP RFC: Deprecations for PHP 7.3

  • Date: 2017-08-02
  • Author: Nikita Popov nikic@php.net
  • Status: Draft


This is a draft RFC for multiple deprecations targeting PHP 7.3. The RFC proposes to deprecate the listed functionality in PHP 7.3 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:

  • TODO


Each feature proposed for deprecation is voted separately. Each vote requires a 2/3 majority, independently of whether it is a language or standard library change. All votes refer to deprecation in PHP 7.3 and removal in the next major version (presumably PHP 8.0).

WDDX extension

Undocumented mbstring function aliases

The functions mbregex_encoding, mbereg, mberegi, mbereg_replace, mberegi_replace, mbsplit, mbereg_match, mbereg_search, mbereg_search_pos, mbereg_search_regs, mbereg_search_init, mbereg_search_getregs, mbereg_search_getpos and mbereg_search_setpos are undocumented aliases of the same functions using an mb_ prefix (e.g., mb_ereg).

Proposed action: Mark the functions as deprecated, so that a deprecation notice is emitted on every call. In PHP 8 these aliases will be removed.

mb_detect_encoding() without strict mode


strip_tags() and fgetss() functions


From some preliminary feedback: We might want to only deprecate the insecure allowed_tags parameter, but keep the “strip all tags” functionality. This function appears to be useful as a relatively simple way of reusing code that outputs HTML in a different context (CLI output, text messages, etc.)

String search functions with integer needle

The following applies to the strpos, strrpos, stripos, strripos, strstr, strchr, strrchr and stristr functions. strpos will be used as a representative example.

String search functions usually operate on a string needle. However, if a non-string is passed, it will be converted to an integer and interpreted as an ASCII codepoint:

$str = "There are 10 apples";
var_dump(strpos($str, "10")); // int(10)
var_dump(strpos($str, 10));   // bool(false)

In a language that relies on transparent type juggling between scalar types, this is problemantic, because the type can easily change depending on the used data source. For example, array keys in PHP are automatically converted to integers, so that using an array key as a strpos needle may not work correctly, because it is interpreted as an ASCII codepoint rather than a string.

Proposed action: Throw a deprecation warning if a non-string is passed as a needle to strpos or one of the above-listed functions. The deprecation warning should note that an explicit chr call may be used instead. In PHP 8 the deprecation warning will be removed and the needle parameter will be changed into a string.

Continue acting on switch

In PHP an argument-less continue inside a switch block behaves the same way as break. In other C-based languages, it will continue the wrapping loop instead. As such, in PHP you need to write continue 2 for an operation that would be just continue in other languages.

We cannot change these semantics for reasons of backwards-compatibility (and arguably wouldn't want to anyway), but we can remove this particular gotcha by disallowing the application of continue to a switch statement and instead force the use of break (at the same level) or a continue at a higher level, depending on which semantics are intended.

In the following some examples are provided to illustrate invalid usages and what they should be replaced with.

switch ($foo) {
    case "bar":
        continue; // INVALID. Replace with:
while ($foo) {
    switch ($bar) {
        case "baz":
            continue;   // INVALID. Replace with
            continue 2; // or
            break;      // depending on the intended behavior
while ($foo) {
    switch ($bar) {
        case "baz":
            while ($xyz) {
                continue 2; // INVALID. Replace with one of:
                continue 3;
                break 2;

Proposed action: Throw a deprecation warning from the compiler if a continue directly targets a switch statement (rather than a loop at a lower or higher level than it). Preferably the deprecation message should include a suggestion for the possible alternatives. In PHP 8 the deprecation will be replaced by a compiler error.

Case-insensitive constants

Previous discussion: https://externals.io/message/100535

TODO (cmb does not want to pursue this, so I will)

Defining a free-standing assert() function

Interacts badly with zend.assertions.


Backward Incompatible Changes

For PHP 7.3 additional deprecation notices will appear. For PHP 8.0 the previously deprecated functionality will no longer be available.

Proposed Voting Choices

Each of the bullet points above will get a separate vote. All votes will require a 2/3 supermajority, independently of whether they are language changes or not.

Patches and Tests

The patches for these deprecations are for the most part trivial, as such they will be provided once the RFC is accepted (or portions of it).

rfc/deprecations_php_7_3.txt · Last modified: 2017/10/27 11:22 by nikic