Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ignium's avatar
Level 21

PHP arrow functions just stopped working

At some point something happened to my Homestead VM, but I don't know what it was. All of my databases were gone (I have migrations) and now any PHP arrow functions I have in my code produce a Symfony\Component\Debug\Exception\FatalThrowableError exception with the message "syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')'". Switching the code from an arrow function

$job_ids = $jobs->map(fn($job) => $job->role_id)->unique();

back to a callback with typical syntax

$job_ids = $jobs->map(function ($job) { return $job->role_id; })->unique();

fixes the error but arrow functions are spread throughout my code base.

I also tried running an arrow function with artisan tinker and it worked just fine, which make this even more confusing to me.

>>> $collection = collect([1,2,3,4]);
=> Illuminate\Support\Collection {#3366
     all: [
       1,
       2,
       3,
       4,
     ],
   }
>>> $collection->map(fn($item) => $item * 2);
=> Illuminate\Support\Collection {#3357
     all: [
       2,
       4,
       6,
       8,
     ],
   }
>>> 

I'm wondering, is there a command I need to run to refresh something?

ETA: I'm running PHP 7.4.0 and Laravel 6.9.0

0 likes
7 replies
ignium's avatar
Level 21

Thanks, I was actually just editing my question to add the the PHP (7.4.0) and Laravel (6.9.0) Versions. This code had worked previously on the "same" homestead box, but I think something somewhere got corrupted.

Sinnbeck's avatar

You can test it by adding a file called phpinfo.php in public with this content (ald call it)

<?php 
phpinfo();
ignium's avatar
Level 21

LOL, it's like you're watching me as I type. I did that and it is in fact now running 7.3.12. Running composer update should fix it, correct?

Sinnbeck's avatar

No composer does not deside what php is version you are running. Try running a reprovision

vagrant reload --provision
ignium's avatar
Level 21

That didn't quite work, but you've set me in the right direction. I might just grab the latest version of Homestead instead. Thanks so much!

Please or to participate in this conversation.