The following are some of the new features PHP 7 1 - Scalar type declarations : if you use the declare(strict_types=1); then the parameter would be strict, i.e folat means float only if you pass anything else it will through the error, declare(strict_types=1); function returnsum(float $a, float $b) { return $a + $b; } returnsum(3.1, 2.1); // output float(5.2) returnsum(3, "2 days"); // Fatal error 2 - Return type declaration : same as scaler type declaration, we can use the return with in a function with strictly. declare(strict_types=1); function add($a, $b): int { return $a + $b; } var_dump(add(1, 2)); var_dump(add(1, 2.5)); // output will be // int(3) // Fatal error 3 - Null Coalescing Operator : if the value is exists and not null, then it returns the first operand, otherwise it returns the second operand. $username = $_GET['username'] ?? 'not define'; // Fetches the value of $_GET['username'] and returns 'not def...
Trying to Learn new things on drupal.