Get a Free Quote
Our Blog

Did You Know About PHP 7.3 New Features?

272 total views
Tarun Bansal
March 29, 2019
PHP-7.3 New Features

PHP developers were juggling between the versions till the new and stable PHP 7.3 released. The version was released after continuous advancements, improvements in code, syntax, language etc.PHP 7.3 is knocking the door and web developers are all ready to embrace the new version.

Web developers, be happy, this new release is all about you. And we are sure the updates can make you better programmers and help you create outstanding applications.As we know, the PHP version is supported for 2 years from its release. This time too, the team of PHP has come up with some decisive and more secured features. And PHP 7 will no longer be supported after 1st Dec’19.Developers will be able to get the new version from the official site itself. PHP 7.3 offers some of the features that had been requested for PHP Web development for years now. Let’s have a look at them.

Flexible Heredoc and Nowdoc Syntaxes:

This feature update definitely draws attention. Developers need space for extra code addition and Heredoc and Nowdoc syntaxes make it ugly and less readable. The code earlier looked like

<?php
class foo {
public $bar = <<<EOT
bar
EOT;
}

But now, PHP 7.3, we can indent the closing marker and the code will look like

<?php
class foo {
public $bar = <<<EOT
bar
EOT;
}

The order of the closing marker sets the white spaces in each line of the body.
And also, it is now not necessary to begin a new line after the closing marker. The code is surely going to look more elegant and attractive.

JSON_THROW_ON_ERRORS:

Developers did not have adequate methods to handle JSON errors since long. That was a huge PHP drawback which needed attention and rectification. Thank God, with this release, PHP provides a new way of handling errors.

This is an extension and not a core feature. This update will change the behavior of json_decode() and json_encode().

Let us explain you with an example of the JSON text.

json_decode(“{“);

 

Here “{“ is not a valid format and so the code will not work. PHP 7.2 was unable to convey to the developers why this code would not work. And the error message that appears as :

json_last_error() === JSON_ERROR_NONE

This will give a syntax error in return and it was cumbersome to deal with the error. 25 votes to 0 were granted in favor of changing this syntax error. The changes that were implemented were:

try {
return json_decode(“{“, JSON_THROW_ON_ERROR);
} catch (JsonException $error) {
$e->getMessage();
}

With PHP 7.3, you can work with exceptions. Json_encode and json_decode now accepts JSON_THROW_ON_ERROR.

So now developers can dig and deal with the errors easily.

Easy communication of JSON in WordPress:

WordPress uses JSON codes. And now, applications can easily communicate with WordPress easily and you can create custom applications to manage WordPress content. Also, the content of different installation is displayed in one domain. There is more you can do with WordPress now.

Trailing commas in function calls:

A different programming language has different variadic functions. Trailing commas are added to a list of elements and properties. They are frequently used when new values are added and thus prevent missing commas errors.
The earlier syntax was :

getStudent($Name, $Birthday)

 

You were not allowed to put a comma after the last property and if done, it would throw an error.
This is no more a problem now. The new syntax is:

getStudent($Name, $Birthday, )

 

They help in debugging a lot. They will be allowed in method calls and enclosures.

Is_countable:

PHP 7.2 did not allow the web developers to count or try a loop on uncountable elements. It showed up a warning. The solution that is used for this is :

if (is_array($santa) || $santa instanceof Countable) {
// $santa is countable}

 

The code checks for an array or countable interface. Using this code will make it look more crowded and so the developers came up with a new version.

The developers introduced a new function called is_countable that will take a variable as a parameter and then return a boolean value.
Now, the code will be

if (is_countable($santa)) {
// $santa is countable
}

 

Isn’t the code easy to remember?

These were the newly added features, now let’s have a look at the features that are removed i.e. Deprecated features.

Case-Insensitive Constants:

Yes, PHP 7.3 no more supports the Case-insensitive constants. They were subjected to inconsistencies and were difficult to use.

image2wbmp():

You will get deprecation warning if you use image2wbmp() any more in the code. This function generated WBMP version of the image which is no more in use now.

To Wrap up:

PHP takes baby steps towards progress and improves over time. It tries to adopt with the ongoing trends of other programming languages. If you want a brilliant application for yourself, you can hire a PHP developer. Enjoy the new PHP coding folks!