5 Latest Features of PHP7
PHP 7 is the most important release of PHP programming language and is touted to be a revolution in the way web applications can be developed and delivered for mobile to enterprises and the cloud. This is the most important change for PHP after the release of PHP 5 in 2004.
1.Scalar Type Declarations:
Type declarations allow the function to require certain types of parameters at call time.
The two types of Scalar type declarations are: one is coercive or you can say it default and other is strict.
Type parameters: strings (string), integers (int), floating-point numbers (float), and booleans (bool).
2.Return Type Declarations:
The Return Type Declaration is the type of value that you want to return from a function.
3.Null Coalescing Operator:
It’s used to check the value. If it is set or null, or in other words, if the value exists and not null, then it returns the first operand, otherwise it returns the second operand.
Example:
“);
// Equivalent code using ternary operator
$username = isset($_GET[‘username’]) ? $_GET[‘username’] : ‘not passed’;
print($username);
print(”
“);
// Chaining ?? operation
$username = $_GET[‘username’] ?? $_POST[‘username’] ?? ‘not passed’;
print($username);
?>
It produces the following browser output −
not passed
not passed
not passed
4.Spaceship Operator:
The Spaceship operator is represented like this <=> this is used to compare two expressions and return -1, 0, 1 when one variable is less than, equal to, or greater than, as compared to the other variable.
Example:
// Integers
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
5.Constant Arrays Using define():
In PHP 7, you can define the array as a constant by using define.
Example:
define(‘NAME’, array(‘Chandar’,’Ram’,’Gugu’));
echo NAME[1]; // outputs “Chandar”
“Cleonix Academy” under “Cleonix Technologies” is a Kolkata based Web development training institute specializing in Website Design, Graphic Design, Web Development, Digital Marketing, Search Engine Optimization. For learning more about PHP contact now.