PHP 7.3 Available on All Servers

October 8, 2018

Update: PHP 7.3 was released for production usage on December 6 and is installed on all servers.

We're happy to announce the release candidate of PHP 7.3 is now available on all servers.

PHP 7.3 brings still more speed improvements to PHP 7, including a faster garbage collector. Additionally, PHP 7.3 includes further cleanup of PHP syntax and function behavior, making the lives of PHP developers easier.

Garbage Collector Improvements

For complicated or long-running scripts with large numbers of structures such as arrays and objects, PHP's garbage collector is invoked to free memory while the script is running. When the garbage collector runs, it slows down your scripts. The improved garbage collector is not only faster, it's also smarter about not repeating work when previous garbage collector runs weren't able to free memory.

New Syntax

More Flexible Heredoc and Nowdoc

Heredoc and nowdoc are syntaxes that make it easy to deal with multiline strings in your code.

Quick refresher: the difference between a heredoc and a nowdoc is that no string parsing (variable substitution) is done inside nowdocs. Essentially, heredocs behave like double-quoted strings and nowdocs behave like single-quoted strings.

Starting with PHP 7.3, using heredocs and nowdocs just got a little easier.

The first change is that the closing marker can now be indented. When indented, it indicates the amount of whitespace to strip from the beginning of each line.

class foo {
    public $bar = <<<EOT
    Some Text
    More Text
    EOT;
}
// Invalid in PHP 7.2 as closing identifier ("EOT") must not be indented.
// Valid in PHP 7.3.

The second change is that other characters are also allowed following the closing identifier. That means you can directly pass the heredoc/nowdoc to a function:

print strtolower(<<<EOT
Some Text
More Text
EOT);

Learn more about the flexible heredoc and nowdoc syntaxes.

Trailing Commas Allowed in Function Calls

Starting with PHP 7.3, a trailing comma in the argument list to a function call is no longer a syntax error.

myfunc(
    "foo",
    "bar",
    123,
);

Note that the trailing comma is only allowed in function call arguments, not function definition arguments.

Learn more about the trailing commas in function calls.

Additional Functionality

New functions: array_first_key() and array_last_key()

These two new functions were added to make it easier to get the first or last key/value of an array.

Learn more about array_first_key() and array_last_key().

New function: is_countable()

This new function allows determining if a variable contains something countable.

Before PHP 7.3 you'd have to use this:

if (is_array($foo) || $foo instanceof Countable) {
    // $foo is countable
}

Starting with PHP 7.3, you can instead use this:

if (is_countable($foo)) {
    // $foo is countable
}

Learn more about is_countable().

New option flag: JSON_THROW_ON_ERROR

Until now, the json_decode() function had an edge case that was unfortunately very common: a result of null could either mean that an error occurred or that the JSON value null was the input being decoded.

PHP 7.3 introduces a new flag, JSON_THROW_ON_ERROR, that can be passed to both json_decode() and json_encode(). When set, instead of invalid input causing these functions to set the global error state, they will instead throw a JsonException.

Learn more about JSON_THROW_ON_ERROR.

Reference assignment using list()

Before PHP 7.3, it was not possible to assign references using list(). For example, the following did not work in PHP 7.2:

$array = [1, 2];
list($a, &$b) = $array;

In PHP 7.3, the above example works as expected.

Learn more about reference assignment using list().

compact() now reports undefined variables

The compact() function creates an array containing variables and their values. Before PHP 7.3, any specified variable names that are not actual variables will be silently skipped by compact(). In PHP 7.3, unset variables such as in the example below where the programmer mistyped 'foo' as 'foz' will cause a notice.

$foo = 'bar';
$baz = compact('foz'); // Notice: compact(): Undefined variable: foz

Learn more about compact() reporting undefined variables.

Deprecated Functionality

There are a few deprecations in PHP 7.3. This functionality is still available in PHP 7.3 but will be removed in a future PHP version. The deprecations include:

  • Defining a free-standing assert() function (overrides the built-in function).
  • String search functions with integer needle (silent conversion of the integer to the equivalent ASCII codepoint).

See the full list and learn more about the deprecations in PHP 7.3.

App Compatibility

Most apps that are compatible with PHP 7.2 will be compatible with PHP 7.3.

Extension Compatibility

If your apps rely on PECL extensions or third-party PHP extensions such as ionCube, you'll need to wait for the extension developer to add PHP 7.3 support.

The good news is that most PECL extensions that support PHP 7.2 already support PHP 7.3. To learn about specific PECL extensions, see our PECL extension documentation which we've updated to include information on PHP 7.3 support.

How to Switch to PHP 7.3

To use PHP 7.3 with one of your apps, go to the app's Settings in ServerPilot and change the Runtime to PHP 7.3.

As always, your servers and apps using PHP 7.3 will automatically receive updates as new PHP 7.3 releases become available. When PHP 7.3.0 is released, all apps using PHP 7.3 RC will automatically begin using PHP 7.3.0.