Really Interested to see the fourth consecutive release by Core PHP team. YES, PHP 7.4 has been released on the 28th of Nov for publicly available.
Let’s go through the major enhancement:
1. Arrow functions provide defined function with explicit by-value scope binding.
$input = 5;
$nums = array_map(fn($n) => $text / $factor, [10, 20, 30, 40]);
2. Class properties support Type declaration.
Now, We can restrict the type of variables that are allowed to be passed. Which certainly avoid doing at the function level.
class Users {
public int $user_id;
public string $user_name;
}
3. Null coalescing assignment operator
it will be most wanted support to avoid simple If statement to check whether the variable is “Set” or “Assign”.
<?php
$arg ??= "user";
?>
4. Unpack Inside Arrays
Now its easier to unpack an array within an Array.
<?php
$name1 = array("John", "Dominic");
$name = array("Ted", ...$name1, "Jake");
// Output
array("Ted", "John", "Dominic", "Jake" );
5. Beyond, addition to the Operators & functions, the Core team has customized Filter.
FILTER_VALIDATE_FLOAT & FILTER_VALIDATE_INT supports min & max range of inputs.
Read More: https://www.php.net/releases/7_4_0.php