Cygnite PHP Framework- Features

5 Best Things You Should Know About PHP 7



Introduction:

Hey Guys!

Last article was “Building A Simple Product Management App Using Angular JS + Cygnite PHP Framework + Bootstrap - Part1”.. Tutorial part2 will be posted coming days. I have drafted this article couple of days back and finally got some time post here. You might have heard about the new major version of PHP is under active development since a year and finally scheduled to release this year. The PHP 7 timeline was approved by core members and aims to release PHP7 in OCT 2015. Even though little delay but we are lucky to see PHP7 end of this year. With the RFC for PHP7 timeline passed (32 to 2). We have now entered into new generation and PHPng is almost ready to speed you up.

The features of PHP7 are fairly enough for advance web application development and making use of latest resources to boost you development. There are lot of talks about PHP5.7, PHP6 or PHP 7. The main reason behind the PHP7 is PHP6 has never reached to stable version, also there are many resources available about PHP6. So PHP community has chosen PHP5.6 to directly PHP7.

Let us get into some details.

1# Performance:

You might have heard about Facebook HVVM out there, to provide you maximum performance for PHP based application. So PHPNG (PHP-Next-Gen) started with the idea to provide maximum performance as Facebook HVVM provides. The performance improvement source was led by ZEND to speed up PHP based applications. As per Zend performance improvement is huge! You can find some benchmark against HVVM here. Without changing single piece of code, just upgrading to PHP7 gives you enormous performance. Deprecating many redundant features also part of performance improvement of PHP7.

2# Scalar Type Hints & Return Types:

While many developers would like to able to declare return type for the function. By default PHP7 will allow developers to declare what kind of return type function is expected to return value. It is almost similar as Type hinting parameters as below.

Example:



  public function isValidUser(int $id) : bool 
  {
     return isset($this->users[$id]) ? true : false;
  }


Above example is similar as Facebook HACK syntax. In this example bool indicates the function will return only boolean value. You can also have look at many example in RFC here.

This allows developers to set expecting strings, int, float or bool to be passed or returned.

3# Spaceship Operator

PHP7 will introduce a new operator called spaceship operator (<= >) otherwise called combined comparison operator. It can be used mostly in sorting and combined comparison. It works like strcmp() or version_compare().

As per the PHP RFC common uses of sorting as below.

Example:

Before PHP7:



  function order_func($a, $b) 
  {
    return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
  }


After PHP7:



  function order_func($a, $b) 
  {
    return $a <=> $b;
  }


It is a beautiful addition to the PHP version. You can find more example here.

4# Additional Features

Apart from above changes there are few new features added into the PHP7 core. I am listing few major changes below.

  • Abstract Syntax Tree: – Another big change on the core. But most likely to be visible to developers. It makes parsing php code easier, less error, and way to build better things in future.

  • Closure::call() : – This is the new method added into core. It allows variable binding at call time rather pre-binding.

  • Null Coalesce Operator : – The coalesce operator or ?? added to the core, which returns the first operand is exists or null.

    Example:

    Before PHP7:

    
    
        $id = isset($_GET[‘id’]) ? $_GET[‘id’] : null;  
    
    
    

    In PHP7:

    
    
        $id = $_GET[‘id’] ?? null;  //equivalent of writing old above syntax 
    
    
    
  • Uniform Variable Syntax : – The main deference of existing syntax and new syntax is to keep consistence and complete variable syntax. Allows advance expressions.

    Example:

    
    
        $$foo['bar']['baz']   interpreted as   ($$foo)['bar']['baz']
        $foo->$bar['baz']()   interpreted as   ($foo->$bar)['baz']()
    
    
    
  • Unicode Codepoint Escape Syntax: – PHP7 introduced syntax to escape unicode codepoint as below.

    Example:

    
    
        echo "\u{202E}Reversed text"; // outputs ‮Reversed text
        echo "\u{1F602}"; // outputs ��
    
    
    

5# Cleanups:

Developers can stop recognizing method name as class name to be a constructor as per PHP4 . It has been controversial early to remove but later has been removed completely as currently we no longer required to warn PHP developer how PHP4 works. This removal added as simplicity.

mysql_* functions are completely removed as extension removed by default.

Multiple default clause support has been removed from the switch case.

Support of ASP tags (<%) and script tags (<script language="php"> </script>) has been removed meaning that you can use those tags to enter php mode.

You can find more, list of deprecated or removed functionalities here, Removed deprecated functionalities in PHP7 .

Conclusion:

Personally I believe recent changes of PHP versions, makes PHP as much more matured language. But it is good message to all PHP developers for building awesome enterprise level applications using latest PHP version.

What do you feel about PHP7 / New RFCs ? Do you think PHP development taking a turn towards better enterprise development? Let me know your thought by passing your valuable feedback or commenting below.

Feel free to share or like us. Keep visiting. Have a nice day.

Follow Us On Facebook Open Source Web Developers by Appsntech facebook group Twitter Open Source Web Developers by Appsntech twitter group Google+ Open Source Web Developers by Appsntech Google group Linkedin Open Source Web Developers by Appsntech, LinkedIn group
Copyright @2011-2013 www.appsntech.com. All rights reserved. Powered By- Sanjoy Dey Productions