22% Faster, A New Era Of Web Development-PHP 7.3 (New Features, Changing Functionalities)

Today where technology is the pilot of our digital world, PHP in Web Development is capturing attention for its capability to build dynamic websites. But are you still stuck as why you people are using PHP? Here are a few points that will clarify your doubts:

  1. Runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  2. Apache, IIS, Nginx, Lighttpd and many more servers are compatible with PHP
  3. Support a wide range of databases
  1. Open source language
  2. Very simple to learn and runs efficiently on the server side

Fix your gaze on PHP 7.3 that has thumped on our doors recently with advanced features, functionalities, circumventing few features that were with early versions and adept quantum of bug fixes. PHP 7.3 has become the talk of the town for the web developers.

1.   Heredoc and Nowdoc syntax

Observation: Requirements of these syntaxes are more relaxed.

Brushing up the terms:

Heredoc: It starts with <<< followed by a marker and ends with the same tag followed by a semicolon.

Example:

print <<<EOT
Welcome to the new version of PHP. Hope you have a world-class experience.
EOT;

Here EOT is an identifier. In here, the last IDENTIFIER must be the first string in a new line for this to work. Also, there must not be any other characters after the previous IDENTIFIER (other than a semicolon, which is optional).

Nowdoc: You need to enclose the identifier with single quotes. No need to parse anything inside a Nowdoc.

Example:

print <<< ‘EOT’
Sea shells she sails on the sea shore.
EOT;

Valid Syntax in PHP 7.2

class foo{
public $bar = <<< EOT
Bar
EOT;
}

Restrictions:

  • The closing marker may not be indented
  • The line with the closing marker may not contain characters like spaces or tabs
  • The first character before the closing marker must be a newline
  • A new line must follow the closing marker

PHP7.3:
Allow indenting the closing marker.
Therefore,
You can write the code as:

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

Note: The closing marker should never be indented further than any other line of the body.

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

The above code will show the Parse Error.

Conclusion: We must use the same indentation characters for the closing marker and any lines of the body.

Termination of heredoc/nowdoc on the same line:

PHP 7.2 Valid Syntax:

$values = [ <<< END
a
b
c
END
, ‘d e f’];

As per the syntax is given above, a new line must follow the marker to terminate the heredoc/nowdoc.

PHP 7.3 Valid Syntax:

$values = [ <<< END
a
b
c
END, ‘d e f’];

It will be the syntax in PHP 7.3. Here the restriction of ending/terminating heredoc/nowdoc with a new line is removed.

For further details of Heredoc and nowdoc can be referred here:
Heredocs and Nowdocs Syntaxes
Heredoc String
Nowdoc String

2.   Allowing a trailing comma in function calls

PHP 7.2: For group namespaces, you should use trailing commas.

PHP 7.3: For function declaration, you should use trailing commas.

The following examples show where trailing commas are extremely useful:

foo(
          $bar,
          $baz,
        );

In early versions, this will throw a PHP Parse error for the trailing ‘,’ after $baz.
PHP Web Development Company can use trailing commas when you’re creating an array with compact(). You should return a formatted string with sprintf(), or when merging an array:

$newArray = array_merge(
            $arrayOne,
            $arrayTwo,
        [‘foo’, ‘bar’],
        );

For debugging with trailing commas and how they are robust with isset() and unset():

var_dump(
    $foo,
    $bar,
    $baz,
    );
=====================
unset(
(
    $foo,
    $bar,
    $baz,
    );
isset(
(
    $foo,
    $bar,
    $baz,
    );

Conclusion: Only the function calls would be affected. The syntax for function declaration will not change.

For further details visit this link

3.  JSON_THROW_ON_ERROR

One of the functionalities that with high regard is looming with PHP 7.3 is the latest technique of handling JSON errors. Though it is not a core feature, it holds the capacity to change the error behavior of json_decode() and json_encode().

Current Situation:

json_decode() returns null on error.
json_encode() returns FALSE on error.

Point to Remember: Both function neither halts execution on an error nor throw any warning.

Proposal for PHP 7.3:
The system introduces a flag. JSON_THROW_ON_ERROR.
Role: On passing this flag, the error behavior of the json_decode() and json_encode() changes.
Observation:

  1. The global error state is left untouched.
  2. If an error occurs, these functions throw a JsonException with the message and code set.

Example:

try{
  json_decode(“{“, false, 512, JSON_THROW_ON_ERROR);
}
catch(\JsonException $exception){
echo $exception->getMessage(); //echoes “Syntax Error”
}

Note:

  1. Parameter parsing errors are not affected by JSON_THROW_ON_ERROR and continue to produce warnings.
  2. An invalid dept parameter passed to json_decode() results in a warning and returned a null which is not affected by JSON_THROW_ON_ERROR.

Additional Resources:

JavaScript Object Notation
json_decode()
json_encode()
json_last_error()
json_last_error_msg()
PHP Language Exceptions

4.  list() Reference Assignment

Reference Assignment: Consider the piece of code given below:
$b = &$a;

As per the above line, $b gets the value of $a but the value is not copied to $b.

Consider the example below:

<?php
$a = 3;
$b = &$a; //$b is a reference to $a
print “$a\n”;  // prints 3
print “$b\n”;  // prints 3

Now if we change the value of $a as given below:
$a = 5;
print “$a\n”;  // prints 5
print “$b\n”;  // prints 5 as well as it is referenced to $a

list() construct:
Current Situation: It can be used to assign variables as if they were in an array.
Lacking: Currently not allowed to assign variable values by reference.
PHP 7.3 Proposal: It should allow us to assign variables by reference with a list().
Current Scenario:

$array = [1, 2];
list($a, &$b) = $array;

With PHP 7.3:

$array = [1, 2];
$a = $array[0];
$b = & $array[1];

Advantage: Assigning multiple variables by reference will become possible.

Additional Resources to refer:

To know more about this thing in detail, you can Hire PHP Developer. He/She Will be able to guide this thing with practical examples.

5.   is_countable Function

Current scenario with PHP 7.2:
An error occurs if count() is used to attempt any non-countable thing. Therefore we are forced to write:

if(is_array($foo) || $foo instance of countable){
// $foo is countable
}

Proposed Plan for PHP 7.3:
The system proposes a function is_countable() which returns true if the given variable is an array or it is is a countable variable is an array, or it is a countable variable, false otherwise. So, you need to modify the code:

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

Additional Links:

6.   array_key_first(), array_key_last()

Current Scenario: You can retrieve the first and the last key of an array by using reset(), end() and key() functions. But the first and the last index can’t be retrieved without changing its inner position. If we go for other options, it will result in a reduction of code reliability and performance.

Proposed Plan for 7.3:
-> array_key_first()
-> array_key_last()
These two functions allow retrieving the first and the last key of a given array without affecting the internal array pointer.

Additional Links:

7.   Argon2 Password Hash Enhancements

Current Scenario in PHP 7.2:
An alternative to Bcrypt algorithm, Argon2 is a hashing algorithm implemented in PHP 7.2. PHP 7.2 introduced the PASSWORD_ARGON2I constant, available to be used in password_* function.
password_hash(‘password’, PASSWORD_ARGON2I);

PHP 7.3:
The system adds a modern alternative of ARGON2: Argon2id

The two early variants were: Argon2d and Argon2i
1. Argon2d – maximizes resistance to GPU cracking attacks.

  • It is faster
  • uses data-depending memory access.

2. Argon2i -uses data-independent memory for password hashing.

  • It makes more passes over the memory to protect from trade-off attacks.

The added one: Argon2id is a hybrid version that combines the Argon2i approach for the first pass over memory, and the Argon2d approach for next passes.

You can implement it:
password_hash(‘password’, PASSWORD_ARGON2ID);

Additional References:

8.   Deprecations

The functions/functionalities removed in PHP 7.3 are:

  1. image2wbmp(): This functions outputs or saves a WBMP version of a given image. This function takes three arguments, an image resource, a filename, and a foreground color. For PHP 7.3, when this will be deprecated, it will throw a fatal error.
  2. Remove Case_Insensitive Constants: PHP supports both case-sensitive and case-insensitive constants. Observations, class constants, global constants declared with const and constants defined with define() are case-sensitive always. Therefore the following changes are proposed for PHP 7.3 study:

A) Deprecate calling define() with the third parameter set to true – PHP 7.3
B) Deprecate accessing case-insensitive constants with a casing different from a report (except for real, false and null) – PHP 7.3
C) Remove odds to declare case-insensitive constants – PHP 8.0
D) Convert true, false and null from special-cased constants into reserved keywords – PHP 8.0

There are more such proposals for deprecations of functions in PHP 7.3. However, there is no surety for depreciation. Here is the list you can go through to have a brief idea about the deprecations.

Statistics for PHP:
1. 22% faster than earlier versions
2. PHP Version Time-Table
3. PHP statistics for WordPress
4. PHP Statistics for Framework

1. PHP Version 7.3 is quick!

To get a broader aspect of why PHP 7.3 is bringing laurels to the PHP family, we will go through the statistics below:

A benchmark test conducted when PHP 7.3.0 Alpha1 was released. From that survey, researchers find that it was 22% faster than PHP 7.0 and 7% more quickly than the current version of PHP 7.2.


PHP 7.3 has got results using Phoronix’s test suite. Significant improvements in both rendering and data processing tests.

2. Versions:

The table below shows the version to date:

3. PHP statistics for PHP

As per the official website of WordPress, 62.6% of the existing sites are using WordPress 4.9. PHP and MySQL Web Development companies should have an idea of these details.

Read also: Top 8 Benefits of CDN that proves it best for your business

4. PHP for Framework

As per the statistics by w3techs, PHP is used by 83.5% of all websites out of which only 16.3% are using version 7.


The diagram below shows the percentage usage of different versions by the developers:

Conclusion:

The all-new PHP 7.3 is all about developers. PHP 7.3 is bringing a lot of new functionalities with it at our doorstep. This article emphasizes all those changes which can be a new phase for every PHP Development Company. If you come across with few more changes, kindly revert in the comment box below and share it here.

hire-cake-php-developer

Disclaimer: We at eSparkBiz Technologies have created this blog with all the consideration and utmost care. We always strive for excellence in each of our blog posts and for that purpose, we ensure that all the information written in the blog is complete, correct, comprehensible, accurate and up-to-date. However, we can’t always guarantee that the information written in the blog correct, accurate or up-to-date. Therefore, we always advise our valuable readers not to take any kind of decisions based on the information as well as the views shared by our authors. The readers should always conduct an in-depth research before making the final decision. In addition to these, all the logos, 3rd part trademarks and screenshots of websites & mobile apps are the property of the individual owners. We’re not associated with any of them.

Mohit Surati

Mohit Surati

A post-graduate in Computer Engineering. Passionate about innovative writing & Content Marketing. A rich vein of experience in writing articles related to WordPress right from plugins, themes, customization, security, WooCommerce & Gutenberg. Pens down his thoughts for eSparkBiz @Custom WordPress Development Company where you can Hire WordPress Developer as per your requirements.

Related Post

Things To Keep In Mind Before Choosing a Payment Gateway For Website

Things To Keep In Mind Before Choosing a Payment Gateway For Website

For any business, it is imperative to choose the best Online Payment Gateway. eCommerce is the fastest growing industry holding immense potential. There’s a multitude…

The Cost Of Developing a Web Application And Its Process

The Cost Of Developing a Web Application And Its Process

Mobile applications dominate the online market. But the contribution by building web applications is also significant. They have been instrumental in acquiring an audience through…

Step-by-Step Guide For Converting Your Idea Into An App

Step-by-Step Guide For Converting Your Idea Into An App

Maybe you are riding your bike, or you are in the shower, or you cannot fall asleep at night, or you are out with a…

get in touch image

Growth Is Just One Click Away

Don’t feel like calling? Just share some project details & our company representative will get in touch. Schedule A Meeting with our Director of New Business

How long would you like the meeting to be?
Get In Touch