PHP 7.2 is here

PHP7.2 was signed as RC6 in 09 Nov 2017 and GA released in Nov 30th's. In Accesto we try our best to keep updated with all new features and changes. Here is a list of the most important things you must know about the new release.

NEW CORE FEATURES

Parameter Type Widening

It is now possible to remove argument type annotations when overriding an inherited method.

class ArrayClass {
  public function foo(array $foo) { /* ... */ }
}


// This RFC proposes allowing the type to be widened to be untyped aka any
// type can be passed as the parameter.
// Any type restrictions can be done via user code in the method body.
class EverythingClass extends ArrayClass {
  public function foo($foo) { /* ... */ }
}

In PHP7.2 the code above will run without any warning.

Allow abstract function override

It is now allowed to override an abstract method with another abstract method in a child class.

It could be useful but mostly in more complex context.

Trailing Commas In List Syntax

A trailing comma in group use statements is now allowed.

Since now we can use syntax like this:

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

There was also an idea to allow trailing commas in another context like in class member lists, use lists for anonymous functions, trait/interface implementations on a class or in function arguments declarations and calls but all of them did not pass the voting stage.

Object typehint

The "object" type annotation is now supported.

function requireObject(object $object) { /* ... */ }

requireObject(json_decode('{}')); // valid
requireObject(new \SomeClass()); // valid
requireObject('try with string'); // invalid

/** You can also use object as return type */
function returnObject() : object { /* ... */ }

Take a while and look at RFC to see more benefits and examples.

SECURITY

Libsodium

As we can read in documentation:

Sodium is a modern, easy-to-use software library for encryption, decryption, signatures, password hashing and more.

And now it is part of PHP Core, how cool is that?

PHP 7.2 tweet Scott Arciszewski

It's great to hear news like that about PHP. Unfortunately, Sodium is not well documented yet on php.net manual, to know more we should reach to Libsodium FAQ and documentation prepared by Scott.

Argon2

PHP7.2 brings new PASSWORDARGON2I constant which can be used in <a href="http://php.net/manual/en/ref.password.php" target="blank">PHP password API functions. It allows to use new hashing algorithm Argon2 - the winner of Password Hashing Competition. Argon2 should be considered as the replacement for old, default Bcrypt algorithm, and in future versions of PHP it will be a standard.

DEPRECATIONS

The methods below are deprecated and will be removed in PHP8.0.

  • __autoload
  • $php_errormsg
  • create_function()
  • mbstring.func_overload
  • (unset) cast
  • parse_str() without second argument
  • gmp_random()
  • each()
  • assert() with string argument
  • $errcontext argument of error handler

You can find the whole list on RFC.

SUMMARY

You can find all upgrade notes connected with PHP7.2 on GitHub. PHP7.2 is not as revolutionary as PHP7.0 was but still introduces some desirable changes. It is another reason to abandon the old versions like 5.6 which is not actively supported and will receive security updates only until 31 Dec 2018. Even 7.0 version finished its active support so it's good time to give a chance to 7.1 or 7.2.

Currently Supported PHP Versions

icon

Ready to make your SaaS Scalable?

Fix most important issues within days from the kick-off

CONTACT US

Related posts