07 Jul' 15

PHP Latest Version — What to Watch Out For?

PHP 7 features

Developers across the world are looking forward to PHP 7, which is scheduled to be released on the November 12, this year. Built on an experimental PHP branch called PHPNG (PHP next generation), PHP 7 shows close to 100% augmentation in performance. Moreover, it also features a reworked and refactored Zend Engine—an open source scripting engine that specifically interprets this programming language. Fret not developers, it will still retain all the language-compatibility that you could ever wish for.

What’s getting developers charged up?

Some of the most important features that have gotten a lot of techies excited are the introduction of return type declarations, novel language features, significant performance improvements, return types, scalar type hints and combined comparison operator.

Though the release is packed with new features and significant performance upgrades, those using an older version of PHP, say PHP 4, will face issues with respect to backward compatibility. This is mostly because PHP 7 is built on an entirely new foundation, and the new features and added performance require certain older features to be incompatible.

In this article, let us focus on some of the most important features of features of PHP 7 to watch out for:

1. Usability and performance

With almost a 100% increment in performance and drastic reduction of bugs, PHP 7 is going to enhance speed, efficiency and productivity. Moreover, those who use a number of servers are likely to see a lower consumption of energy, making this one of the greenest PHP versions so far. Though some features maybe incompatible, PHP developers will not have to change codes much. Performance is likely to increase by 25% to 70%. As PHPNG is built into PHP 7, the amount of CPU instructions will reduce drastically, leading to a doubling of performance.

2. Spaceship operator

The spaceship operator (<=>) (also known as the Combined Comparison operator) is a great addition to PHP.  PHP developers will no longer feel limited to just strings. They can use this feature on arrays, integers, floats and others. Writing ordering functions will no longer need to be verbose and they can be written in a simpler way. Similarly, multiple columns can be sorted easily, too.

3. Scalar type hints and return type declarations

Developers can declare which return type a function is supposed to have. Developers can declare if they expect floats, ints or strings to be returned or passed, thanks to the new scalar types. Both argument type hints and return type declarations support scalar types.The return types supported by PHP 7 are callable, float, strong, self, parent, class and interface names, closure, array and bool, apart from string, int and float.

For example:
function foo(): array {
return [];
}

4. Ternary operator

PHP 7 will also have an improved isset ternary operator. It is like shorthand notation that eases the performance of isset() checks. This new syntax is common in applications hence was developed.

Example:

$age = isset($_GET[‘age’]) ? $_GET[‘age’] : ’10’;
// will be changed in PHP 7
$age = $_GET[age] ?? ‘10’;

5. Security

A new feature, Filtered unserialize() has been added to PHP 7, which is giving it a new layer of security, specially designed to address untrusted data and unserializing objects. This new feature will help developers to avert un-serialized injections.

For example:
$info = unserialize($foo, [“base_classes” => false]);

// converts all objects into __PHP_Incomplete_Class object except those of DevClass and DevClass2
$info = unserialize($foo, [“base_classes” => [“DevClass”, “DevClass2”]);

// default behaviour (same as omitting the second argument) that accepts all classes
$info = unserialize($foo, [“base_classes” => true]);

PHP 7 – a promising way ahead

Other than the features mentioned above, PHP 7 comes with other promising features that developers may find interesting such as the inclusion of anonymous classes, Unicode codepoint escape syntax, closure call method, group use declarations, generator return expressions and others.

The improved performance, added features and fixing of bugs are likely to make PHP 7 one of the most used server-side scripting languages in the development community. With its far-reaching influences on WordPress and other CMS communities, the new version will be the topic of conversation during PHP developer rendezvous in the coming days.

Sougat Hajra

Global Delivery Manager

Sougat is the Global Delivery Manager with Code{UR}Idea. He is an expert with e-Commerce- development, deployment and design.

Comments

  1. icon

    Mike Moses, July 7, 2015 at 2:20 pm Reply

    Excellent write up Sougat, very informative.

Leave Comment

Your email address will not be published. Required fields are marked *