- Thursday, 2019-01-17 20:11
- Here are my condensed lists of PHP 7.1, 7.2, and 7.3 features I'm looking forward to. As usual in order of personal preference.
- Class constants can be made protected and private.
- Nullable type declarations allow to replace
function ( ValueType $value = null )with
function ( ?ValueType $value ). The only difference between the two is that the new syntax does not make the parameter optional any more.
voidas a return type.
- We can replace
array|Traversabletype hints with
is_iterable()goes along with this new pseudo type.
catch ( TypeAException | TypeBException $ex )
list()supports keys. This is pretty significant. Before, we could only deconstruct numerically indexed, non-sparse arrays.
- Instead of
list( $a, $b ) =, we can now write
[ $a, $b ] =.
- We can replace
substr( $string, -1 )with
$string[-1]. I'm not sure if we should, but we can.
- We can finally replace
\stdClasstype hints with
mb_chr()as well as
- Having dealt with the oddities of IEEE floating point numbers before, I find the new constants PHP_FLOAT_MIN, PHP_FLOAT_MAX, PHP_FLOAT_EPSILON, and PHP_FLOAT_DIG fascinating. Even if they won't end in a lot of code, they give some insight into how floating point numbers work.
- Regular expressions support the
/Jmodifier, which makes it possible to have the same named capturing group multiple times in the regular expression. Note that the inline
(?J)was already supported before.
- PREG_UNMATCHED_AS_NULL (instead of empty strings) will definitely come in handy.
- The GD extension can read and write BMP files now. Uh, what? o_O? In exchange, a few awkwardly specific WBMP conversion functions got deprecated.
create_function()got deprecated in favor of anonymous functions.
each()got deprecated in favor of
mb_strtoupper( 'Straße' )now produces »STRASSE«. I find this a super-welcome addition. But it can also have massive implications, like changing the result of string comparisons.
is_countable()is true for arrays and objects that implement Countable.
array_key_last()can often act as a much cleaner replacement for complicated code utilizing
array_keys(), or awkward combinations of
- Array destructuring can be combined with references:
list( &$a ). Same for the new
[ … ] =syntax.
- The heredoc syntax for strings became more flexible. Most notably: the closing marker can be indented.
Kommentare zu diesem Beitrag können per E-Mail an den Autor gesandt werden.