Get "PHP 8 in a Nuthshell" (Now comes with PHP 8.3)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Top fetaures of PHP 7.3

PHP development team has just released PHP 7.3 with general availability. This release brings general improvements along with some new features. Even though this is a stable release, the team hasn’t provided concrete migration guide if you want to migrate from the older PHP versions. Maybe they will release those on a later date.

So, meanwhile let’s look at all the new features which are available in PHP 7.3.

More Flexible Heredoc and Nowdoc Syntax

The closing marker for doc strings is no longer required to be followed by a semicolon or newline. Additionally the closing marker may be indented, in which case the indentation will be stripped from all lines in the doc string. This means that the following syntax will be valid.

class foo {
    public $bar = <<<EOT
bar
    EOT
}
// Identifier can be indented now
// Also notice there is no semicolon after closing marker

Trailing Commas are allowed in Calls

Trailing commas in function and method calls are now allowed in PHP 7.3. A trailing comma has been allowed in array syntax since forever-ever, and in grouped namespace syntax since PHP 7.2. Below for example,

$foo = [
    'foo',
    'bar',
];

The similar syntax can now be utilized for function calls as well. Take for the example,

unset(
    $foo,
    $bar,
    $baz,
);

Array Destructuring supports Reference Assignments

Array destructuring now supports reference assignments using the syntax [&$a, [$b, &$c]] = $d. The same is also supported for list().

CompileError Exception instead of some Compilation Errors

A new CompileError exception has been added, from which ParseError inherits. A small number of compilation errors will now throw a CompileError instead of generating a fatal error. Currently, this only affects compilation errors that may be thrown by token_get_all() in TOKEN_PARSE mode, but more errors may be converted in the future.

An is_countable() function

PHP 7.3 comes with a is_countable() which can be used to verify if contents of a variable is an array or an object implementing Countable.

var_dump(is_countable([1, 2, 3])); // bool(true)
var_dump(is_countable(new ArrayIterator(['foo', 'bar', 'baz']))); // bool(true)
var_dump(is_countable(new ArrayIterator())); // bool(true)
var_dump(is_countable(new stdClass())); // bool(false) 

This were the new features which I felt are the key ones of PHP 7.3. If you wish to check out the PHP 7.3, you can download it from here or check the changelog from the official site.

Learn the fundamentals of PHP 8 (including 8.1, 8.2, and 8.3), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article? Consider leaving a

Tip

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?