Thiemos Archiv
- Thursday, 2019-01-17 19: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 )withfunction ( ?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 withiterablenow.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 withobject. mb_chr()as well asmb_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
/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 offoreach.
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()andarray_key_last()can often act as a much cleaner replacement for complicated code utilizingarray_keys(), or awkward combinations ofend()andkey().- 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.
Not sure what to think of the mb_strtoupper() modification being introduced now after big ß support is pretty common ;o
https://github.com/tomaes/primevis/issues/1
(besser spät als nie? ;)