Welcome to LetsNurture Engineering Blog!

We have witnessed Facebook as a perceptional change in how people interact with others, also it has triggered the change in the technology stack; specially for PHP. Inspired from Facebook HVVM for Just In Time compilation in PHP, the source team led by ZEND added huge performance improvements to the PHP released as PHP7. We never witnessed PHP6 though as it never reached to stable version after PHP5.6

In this post we are going to list out some of changes and new features quickly.

Functions changed : there are plenty listed on php.net website for documentation but most commonly used ones are
mktime() – the is_dst for day light saving parameter has been removed (default UTC).
preg_replace() – now “\e” modifier has no effect.
setlocale() – Only LC_* constants allowed.
substr() – expect empty string instead of FALSE.

Removed extensions : Commonly used mssql, mysql extensions has been removed now. Instead use sqlsrv or pdo for mssql, mysqli for data connections.

There have been multiple changes but listing them all will be too much information here, so only frequently used functions / extensions have been listed above.

Now as a programmer how it will affect you?
Well, there are good news due to JIT for performance without doubt but you might need to see it in action by trying yourself. Below are some changes in our way of writing PHP code just because of PHP7.

Return Types: Since days of C language we had envisioned the return types for functions, and now its here in php too. It helps a lot to avoid var dump and echo statements to dig down the reason in debug cases frequently as you can specify and expect exact return type.

prior PHP7

public function someFunction($inputType) 
{
  // some business logic
  …..
 return true;  // also you can return 1234 or string or any type
}

PHP7

public function someFunction($inputType) :bool
{
  // some business logic
  …..
 return true;  // RETURN TYPE is set now so only bool
}

Null coalesce operator: The coalesce operator ?? has been added to core thus log null condition match syntax has become shorter and cleaner.

prior PHP7

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

PHP7

$myVariable  = $_GET[‘inputParam’] ?? null;

Changes to list(): Existing RTL way is replaced with LRT with a note that empty list() are not allowed.

prior PHP7

list(array[], array[], array[]) = [12, 22, 33];  // array(3) { [0]=> int(33) [1]=> int(22) [2]=> int(12) }

PHP7

list(array[], array[], array[]) = [12, 22, 33];  // array(3) { [0]=> int(12) [1]=> int(22) [2]=> int(33) }

Closure::call(): Now function calls are with run time binding rather than pre-binding, this has been added to core and kind of essential for object oriented programming.

prior PHP7

class Foo { private $x = 3; }
$foo = new Foo;
$foobar = function () { var_dump($this->x); };
$foobar->call($foo); 

// above prints E_ERROR : type 1 — Call to undefined method Closure::call()
PHP7

class Foo { private $x = 3; }
$foo = new Foo;
$foobar = function () { var_dump($this->x); };
$foobar->call($foo); 

// Now above prints int(3)

How you are getting along with PHP7? Do you like it over PHP5.6?
On performance note PHP5.6 introduced OpCache which was already good for improved performance by good margin but with changes in core with JIT support new version just wins head down, only possible constraint is “the change” as even experienced programmers might need to align themselves ;).

Ravi Tiwari

Geeky mind, nerdy heart, father of 2 and occasional day dreamer ;)

Want to work with us? We're hiring!