DEV Community

Discussion on: Yes, PHP is Worth Learning/Using in $CURRENT_YEAR

Collapse
 
bdelespierre profile image
Benjamin Delespierre • Edited

Arrow functions are kewl too

$b = 2;
$f = fn($a) => $a + $b;
$f(1); // 3
Enter fullscreen mode Exit fullscreen mode

Enums are kewl too (PHP8.1)

Fibers are kewl too (PHP8.1) <= BIG game changer here!

Array destructuring in loops are awesome too:

$a = [[1,2,3],[4,5,6]];
foreach ($a as [$b, $c, $d]) {
    var_dump($b, $c, $d); 
}
Enter fullscreen mode Exit fullscreen mode

Iterators & generators are awesome in PHP

function get_php_files(...$paths): Generator
{
    foreach ($paths as $path) {
        if (is_file($path)) {
            yield new SplFileInfo($path);
            continue;
        }

        $it = new RecursiveDirectoryIterator($path);
        $it = new RecursiveIteratorIterator($it);
        $it = new RegexIterator($it, '/\.php$/', RegexIterator::MATCH);

        yield from $it;
    }
}
Enter fullscreen mode Exit fullscreen mode