Thiemo Mättig

Thiemo’s Weblog

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.

Whats new in PHP 7.1?

  • 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.
  • void as a return type.
  • We can replace array|Traversable type hints with iterable now. 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.
Whats new in PHP 7.2?
  • We can finally replace \stdClass type hints with object.
  • mb_chr() as well as mb_ord() are new.
  • 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 /J modifier, 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 foreach.
Whats new in PHP 7.3?
  • 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_first() and array_key_last() can often act as a much cleaner replacement for complicated code utilizing array_keys(), or awkward combinations of end() and key().
  • 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.
About floating point: It´s always funny to see that how hard (impossible?) it is to abstract the underlying implementation away

Not sure what to think of the mb_strtoupper() modification being introduced now after big ß support is pretty common ;o
TS
The Law of Leaky Abstractions: »All non-trivial abstractions, to some degree, are leaky.«
Thiemo
mehr schreiben


(Links wie gewohnt formatieren.)

[ < Zurück zur Übersicht ]

Impressum & Datenschutz