Great News for PHP developers! PHP Version 5.6.0 is live. This new version has 158 bug fixes, 39 new additions and 18 new implementations in its features. They can help you to improvise the coding of your websites. Let’s see how its new features can help you to do so.

Create exponentials with ease

In previous version of PHP, you need to use the Pow(a, b) function to create an exponential of a^b. But, in the new version of PHP, you just have to use the ** operator. In addition to that, you can also use ** = operator as well.  This will help you to avoid having too many Pow() functions, which will help you to minimize the functional errors.

Syntax of PHP 5.5

Pow(a, b)

Syntax of PHP 5.6

a**b

Constant scalar expressions

Never before in the version of PHP it was possible to include numbers and strings in a scalar expression. Now you can define one scalar expression with a combination of numbers and strings. You can also define a constant name (string) in other scalar expressions. Let’s see a live example.

Previously your coding may look like this.

Const a =1

Const b = 1*2

Now you can use it in this way.

Const ONE = 1

Const TWO = ONE*2

This feature will be very useful to write the codes when you are dealing with number of constant values. It will also help other developers to read the codes.

Improve the Syntax of your variadic functions

A Vardiac function is a function which accepts a variable number of arguments. In previous versions of PHP, you had to use the func_get_args(), now you just have to use the …operator. The advantage of this change is that the codes it doesn’t have to do any king of splicing after the func_get_args() function. Let’s check out the difference in syntax of previous version and this version.

Variadic functions in PHP 5.5

class MySQL implements DB {

protected $pdo;

public function query($query) {

$stmt = $this->pdo->prepare($query);

$stmt->execute(array_slice(func_get_args(), 1));

return $stmt;

}

// …

}

$userData = $db->query(‘SELECT * FROM users WHERE id = ?’, $userID)->fetch();

Variadic functions in PHP 5.6

class MySQL implements DB {

public function query($query, …$params) {

$stmt = $this->pdo->prepare($query);

$stmt->execute($params);

return $stmt;

}

// …

}

What experts say about the security of this new version?

Experts say that the new version is safer and more secure than its predecessor.  Previously, when you download a resource via HTTPS utilizing file_get_contents() syntax, it didn’t check for certificates. But now in the current version it does.

In the previous versions, Mcrypt extensions accepted missing initialization vectors or incorrect keys. But in this version they have improvised the security.

Final word

Use the above-mentioned techniques, improve the codes and share your experience in coding with the new version of PHP – 5.6.0.