DEV Community

Discussion on: How to write a different PHP?

Collapse
 
rehmatfalcon profile image
Kushal Niroula

It would have been much more useful if the arrow syntax could be used for multiline function.

I actually like that it closes over the value of the enclosing scope. It would have been much more useful when creating an anonymous function that uses data from the enclosing scope.

<?php
function create($name,$age) {
    $this->em->transactional(fn() {
        $person = new Person($name,$age);
        $this->em->persist($person);
        $this->em->flush();
    });
}
Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him) • Edited

Yes, it would have been awesome. Maybe in the later version, they will add such a feature.