PHP 7.2 has been officially released as of November 30. Argument type declarationsSince PHP 5 we are allowed to specify in a function’s declaration the argument type that is expected to be passed. If the given value is of an incorrect type, then PHP throws an error. Since PHP 7.2 type hints can be used with the object data type, and this improvement allows to declare a generic object as argument of a function or method. Object return type declarationsIf argument type declarations specify the expected type for a function’s arguments, return type declarations specifies the expected type of the returning value. As of PHP 7.2 we are allowed to use return type declarations for the object data type.
PHP 7.2, we are allowed to omit a type in a subclass without breaking any code. This proposal will allow us to upgrade classes to use type hints in libraries without being required to update all subclasses.
Trailing commas in list syntax
A trailing comma after the last item in arrays is valid syntax in PHP, and sometimes it’s encouraged in order to easily append new items and avoid parse errors due to a missing comma. Since PHP 7.2 we are allowed to use trailing commas in grouped namespaces.
Argon2 is a powerful hashing algorithm which was selected as the winner of 2015 Password Hashing Competition, and PHP 7.2 will bring it to us as a secure alternative to the Bcryptalgorithm.
The new PHP version introduces the PASSWORD_ARGON2I constant, that can now be used in password_* functions:
password_hash('password', PASSWORD_ARGON2I);
Unlike Bcrypt, which takes only one cost factor, Argon2 takes three cost factors distinguished as follows:
A memory cost which defines the number of KiB that should be consumed during hashing (default values are 1<<10, or 1024 KiB, or 1 MiB)
A time cost that defines the number of iterations of the hashing algorithm (defaults to 2)
A parallelism factor, which sets the number of parallel threads that will be used during hashing (defaults to 2)
Three new constants define default cost factors:
PASSWORD_ARGON2_DEFAULT_MEMORY_COST
PASSWORD_ARGON2_DEFAULT_TIME_COST
PASSWORD_ARGON2_DEFAULT_THREADS