
Lead Image © MIR, Fotolia.com
New features in PHP 7.3
Prime Numbers
PHP version 7.3 [1] became available at the end of 2018. At first glance, the innovations do not appear spectacular, but they could disrupt existing scripts. That said, with deprecations and end of support for older PHP versions, website owners might want to consider switching to the new version as soon as possible.
PHP 7.3 not only throws some ballast overboard, it also introduces syntax changes. In everyday life, programmers may particularly notice the switch to PCRE2 (Perl-compatible regular expressions, version 2), the changed behavior in multibyte string functions, and the more flexible Heredoc and Nowdoc syntax.
The Here and Now
The Heredoc syntax simplifies the assignment and output of longer text by replacing strings in double quotation marks with text between delimiters. For example, if $name = "Hans Hansen";
, the Heredoc
$output = <<<EOT My name is: "$name". EOT;
would output My name is: Hans Hansen.
In a Heredoc, the <<<
operator is followed by an identifier that signals the beginning of text. The text continues until the identifier appears again to mark the end of the Heredoc.
Nowdoc syntax was introduced in PHP 5.3.0. It behaves like text in single quotes, which PHP does not interpret. If you change the first line of the example to
$output = <<<'EOT'
$output
would display the text My name is: "$name".
In older PHP versions, a semicolon and a blank line always followed the second identifier at the end of the string. The expression EOT; echo $output;
was not allowed, for example. In PHP 7.3, this constraint has been eliminated for both Heredoc and Nowdoc. Moreover, developers can finally indent the text and the identifier:
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
