PHP

PHP 7.2 What’s new features and improvements

PHP 7.2 features
64 / 100

PHP 7.2 has released officially with new features, functions and several smaller core improvements. PHP 7.2 has come with some new security functions and language legacy clean ups. it provides a big performance boost and it is faster than PHP 7. Here I will describe about the new released features that are mentions as below.

PHP 7.2 features

  1. Parameter type widening
  2. Abstract class Parameter type widening
  3. Trailing comma in list syntax
  4. Object Type Hinting
  5. New Sodium extension
  6. Argon2 in password hash

Now start exploring  new released features.

Parameter Type widening

PHP does not allow parameter type change between parent class and child class or interface until PHP 7.2. See the following code.

class Parentclass{
public function sum($numbers){}
}

class Childclass extends Parentclass{
public function sum(array $numbers){}
}

In the above code we changed the parameter type of function sum($numbers) to sum(array $numbers).

PHP 7.2 allowed omit a type in childclass that would be helpful to upgrade classes to use typehints in third party libraries.

 

Abstract class Parameter type widening

In PHP 7.1 or previous version, we can not change the type of parameter of parent abstract class in child class.

abstract Class Parentclass{
abstract function sum(array $numbers){}
}

abstract  class Childclass extends Parentclass {
abstract function sum($numbers){}
}

 

Trailing comma in list syntax

PHP 7.2 now supports trailing comma in multiline arrays look like the following.

$foo=[
‘foo’,
‘baz’,
];

 

Trailing comma in group statements

Use Foo\Bar\{
 Foo,
 Bar,
 Baz,
 };

Trailing comma is proposed to the all list like places

  • Grouped namespaces
  • Function/Method arguments
  • Interface implementation
  • Trait implementation
  • Class member lists
  • Inheriting variables from parent scope to anonymous function

Object type hinting

PHP 7.2 provide return type declarations of a variable that is expected to return by a function.

class Test{
public $arg=”Return type declaration”;
}

function myfunction(Test $ob):object{
return $ob;
}
echo myfunction(new Test)->$arg;

In the above function we can define the return type object of myfunction()

New Sodium extension

A new extension includes into core library named libsodium library.  libsodium is a cross platform, cross language library for encryption, decryption, password hashing.

 

Argon2 in password hash

PHP 7.2 supporting the Argon2 password hashing algorithm which is an award winning, powerful hashing algorithm.

password_hash('password', PASSWORD_ARGON2I);

performance and speed

php 7.2 performance

  • PHP 7.2 and PHP 5.2 performance comparison says that PHP 7.2 is 400 times faster than PHP 5.2
  • PHP 7.2 could execute almost three times as many transactions per second as compared to PHP 5.6.

Conclusion

PHP 7.2 is contains several language improvements  like type widening, object type hinting, libsodium extension support and argon 2 hashing algorithm. Many other core improvements that are not discussed here you can see here http://php.net/releases/7_2_0.php.
You can test PHP 7.2 and experience the new features.

Downloads

http://php.net/downloads.php

Changelog

http://php.net/ChangeLog-7.php#7.2.2

http://php.net/ChangeLog-7.php#7.1.14 

Laravel 5.6 also going to release see here

Please follow and like us:

About Viren-Dra Yadav

Tech Enthusiast | Open Source Lover | WordPress Explorer | Mad for Speed | DevOps Engineer | AgriTech
View all posts by Viren-Dra Yadav →

Leave a Reply

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