December 2018 has welcomed the latest and greatest PHP 7 version – PHP 7.3! Of course, it’s packed with additional features, fixes, performance boosts and functionalities in order to improve your WordPress user experience.
2019 update – if you want to know more about the companies that top the game in Web Development, we suggest this resource: Top Web Developers Of 2019 .
More relaxed Heredoc and Nowdoc syntax requirements
- It’s not necessary for the ending token to be the first string of the line;
- Spaces and tabs can be used for the ending token indentation;
- Pay attention to the spaces and tabs as they cannot intermix;
- PHP 7.3 also means saying goodbye to the exact number of the ending token white-space characters within the heredoc and nowdoc expression;
- Pay attention to the fact that more white-space characters in the ending token compared to the number within the expression will result in an error;
- Still, it’s possible to add more expressions after the ending token with no error.
Make sure that your heredoc/nowdoc string literals don’t have the same token as the line’s first positive character; this will result in an error.
Allow trailing comma in function and method calls
This is a rather simple change that will make things easier for variadic parameters functions.
In general, trailing commas are now allowed in function and method calls with no effect on declarations.
Note that one can’t use commas to skip arguments or have more than one comma at the end.
Option to make json_encode and json_decode throw exceptions on errors
It may have taken years for this feature to arrive, but with the new PHP 7.3 for WordPress website you can finally start using it. Basically, you can now make JSON operations without piling up the json_last_error every single time.
References in list()
PHP 7.3 will now allow you to assign a variable from the whole list – as long as it is referencable.
is_countable() function is introduced
Instead of boilerplate code, PHP 7.3 for WordPress has introduced a function that returns in case of a countable variable – is_countable(). While one had to deal with warnings and constant checking for whether a variable is countable or not in the past, the whole ordeal should be quite simplified now.
Bye-bye to image2wbmp() function
There’s really not much to say about this particular change in PHP 7.3 for WordPress. Essentially, if you’ve used image2wbmp() function for WBMP image format, just replace it with the new one – imagewbmp.
Welcome array_key_first() and array_key_last() functions
Even though PHP contains 75 array functions, retrieving the first and last array keys wasn’t possible without going through the more complex process of array pointer modification or all-keys retrieval.
But, PHP 7.3 for WordPress introduced two new functions – array_key_first() and array_key_last(), which makes things a lot simpler when it comes to retrieving first and last array keys.
PCRE to PCRE2 migration
The library for Regular Expressions, PCRE got its own update with PHP 7.3. So, instead of the 8.x version used in PHP 7.2, PHP 7.3 introduced PCRE2 library for Regular Expressions.
Even though this change is rather subtle, pattern validation of the new library is more aggressive, which can cause some errors on occasion.
This primarily includes the pattern compiling issue under the new library. Essentially, PCRE2 requires the hyphen from the code to be moved to the end or escaped in order to function properly.
Make sure to test out the patterns to see whether there are any compilation errors present.
Deprecate FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED flags used with FILTER_VALIDATE_URL
The change, in this case, is pretty simple; in order to have strict URL validation, you could basically use two extra flags aside from the common filter_var($var, FILTER_VALIDATE_URL). These two flags are FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED.
Now, the mentioned flags are deprecated and considered implied with FILTER_VALIDATE_URL, which is why it’s perfectly fine to just get rid of them.
Case-insensitive constants are deprecated as well
This may require a bit of manual work, as you don’t have a default enabler that will declare constants case-sensitive. There will be a helpful warning for declared case-insensitive constants.
There shouldn’t be too many problems with this particular process, as it was required to declare case-insensitive constants explicitly before.