The Wayback Machine - https://web.archive.org/web/20240706034317/https://www.geeksforgeeks.org/php-5-vs-php-7/
Open In App

PHP 5 vs PHP 7

Last Updated : 19 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

PHP is a server side scripting language designed for web development by Rasmus Lerdorf in 1994. Since its launch in 1994 PHP has become an industry standard supporting almost 80% of the websites ( 79.8% to be precise) with its closest competitor being ASP.Net at 19.8% and others like Ruby, Java trailing far behind.

The PHP development team released the latest version of PHP: PHP 7 claiming it to be twice as fast as its predecessor PHP 5. So, is migrating to PHP 7 really worth it?

Let’s get into some details:

Advantages:

  1. Performance: As per Zend Technologies, the performance improvement is huge!! Just upgrading to PHP 7 gives enormous performance upgrades. Hence, PHP 7 is often termed PHPNG (PHP – Next Gen) taking the performance of your code to a whole new level.
  2. Return Type: Developers have been raising their eyebrows over not being able to declare a return type for their function. This has somewhat been taken care of in PHP 7 where you will be able to declare what type of value will be returned. Eg. :
    public function area (float $r) : float
    {
       return 3.14*$r*$r;
    }
  1. Spaceship Operator: As the name suggests, the spaceship operator introduced is certainly from a different world. It can be mostly used in sorting and combined comparison. Example:

Before:

    function sort ($a,$b)
    {
        if ($a>$b)
            return 1;
        else if ( $a ==$b)
            return 0;
       else
            return -1;
    }

 In PHP 7:

    function sort ($a,$b)
    {
       return $a < = > $b;
    }
  1. Null Coalesce Operator:The coalesce operator (??) returns result of its first operand if it exists, or null if it doesn’t. Eg. :

Before:

   if (isset ($_GET [‘name’]))
   {
        $name = $_GET [‘name’];
   }
   else
        $name = null;

In PHP 7:

$name = $_GET [‘name’]?? Null;

Additional Features:

  • Unicode Codepoint Escape Syntax : PHP 7 introduced syntax to escape Unicode codepoint as below :
          echo “\u{202E} Reverse “;      // This outputs : esreveR
  • Deprecation of mysql_* functions: PHP 7 has deprecated all mysql_* functions, now developers have to use mysqli (the intelligent version of MySQL) instead.

 Cons:

While there is no major downside to it, but to just point out, here is a list of some:

  1. A lot of extensions are not ready yet for PHP 7.
  2. If anyone has functions like “ereg” and “mysql” buried deep inside their code base, they are gonna strike a Backward Compatibility wall as these functions are deprecated and, it is going to be a real pain in the behind to upgrade.

Let us look at more differences between PHP 5 and 7 in the below table –

S.No PHP 5 PHP 7
1. 64-bit integers as well as large files are not supported as it do not have 64-bit support. Having a 64-bit support , it enables the programmer to use native 64-bit integers and large files.
2. Handling of fatal errors is a bit challenging. Handling of fatal errors is quite simple.
3. Anonymous class concept is not present. To expedite the execution time , anonymous class is used.
4. Simultaneously performing several activities was difficult. This issue has been resolved in PHP 7 and it allows seamless execution of a variety of tasks.

Conclusion:

PHP 7 is the future of PHP and all the applications will need to upgrade to PHP 7 sooner or later. Like all major revolutions throughout history, the PHP 7 revolution will also be spilling some blood before producing something awesome.

How do you feel about PHP 7 in general? Is it heading in the right direction? Let us know!!

This blog is contributed by Ayusch Jain. If you also wish to showcase your blog here, please see GBlog for guest blog writing on GeeksforGeeks.



Similar Reads

PHP | Get PHP configuration information using phpinfo()
PHP provides us with a built-in function phpinfo() which gives us the details about the PHP version and PHP configuration of PHP installed in our system. To know about the Configurations and PHP version which is installed in your computer, a simple PHP script can be used. The script consists of a PHP function called "phpinfo()" which outputs inform
2 min read
How to include content of a PHP file into another PHP file ?
Including the content of a PHP file into another file reduces the complexity of code by reducing the code and improving its modularity by splitting the code into different files so that it is easy to understand and manage. There are two ways to do it by using the following PHP functions. PHP include() Function: It will show the warning if the file
2 min read
What is New in PHP Type Hinting Support in PHP 8?
PHP 8 introduced several enhancements and new features related to type hinting. That will check the code for their respective type so that we can use our code efficiently. These are the following features used in PHP Type Hitting Support: Table of Content Union TypesMixed TypeStatic Return TypeInheritance of Contravariant ParametersInheritance of P
3 min read
LAMP installation and important PHP configurations on Ubuntu
PHP is the Web development (Server Side Scripting Language) written and developed for web developers.It was developed by Rasmus Lerdorf in 1994, for maintaining his personal homepage. Later he added the feature to communicate with web forms and to connect with databases, named it as Personal Home Page Tools (PHP), Lerdorf wrote those using C binari
5 min read
PHP | imagecreatetruecolor() Function
The imagecreatetruecolor() function is an inbuilt function in PHP which is used to create a new true-color image. This function returns a blank image of the given size. Syntax: resource imagecreatetruecolor( $width, $height ) Parameters: This function accepts two parameters as mentioned above and described below: $width: This parameter is used to s
2 min read
PHP fpassthru( ) Function
The fpassthru() function in PHP is an inbuilt function which is used to read data from a current position from a specified file until end of file and then write the result to the output buffer. The file which has to be read is sent as a parameter to the fpassthru() function and it returns the number of characters passed on success or FALSE on failu
2 min read
PHP | ImagickDraw getTextAlignment() Function
The ImagickDraw::getTextAlignment() function is an inbuilt function in PHP which is used to get the alignment applied when annotating with text. It helps to format the text by making it stick to left, right or middle. Syntax: int ImagickDraw::getTextAlignment( void ) Parameters: This function doesn’t accept any parameter. Return Value: This functio
2 min read
PHP | Ds\Sequence last() Function
The Ds\Sequence::last() function is an inbuilt function in PHP which is used to return the last element from the sequence. Syntax: mixed abstract public Ds\Sequence::last( void ) Parameters: This function does not accept any parameters. Return value: This function returns the last element from the sequence. Below programs illustrate the Ds\Sequence
1 min read
PHP | array_udiff_uassoc() Function
The array_udiff_uassoc() Function is an inbuilt function in PHP and is used for distinguishing between two or more array. The function computes the differences array by use of two user-defined functions with the additional index key. It compares both data and index by use of callback functions and returns the difference. Syntax : array_udiff_uassoc
5 min read
How to generate Json File in PHP ?
In this article, we are going to generate a JSON file in PHP by using an array. JSON stands for JavaScript object notation, which is used for storing and exchanging data. JSON is text, written with JavaScript object notation. Structure: {"data":[ { "sub_data1":"value1", "sub_data2":"value2","sub_data_n":"value n" }, { "sub_data2":"value2","sub_data
3 min read
three90RightbarBannerImg