Hey there DEV.to community.
PHP is one of the most discussed programming languages out in the development world. Some people call it a dead progra...
For further actions, you may consider blocking this person and/or reporting abuse
I never use arrow function. If I wanted to use javascript, I would use it not php. Arrow function destoys the readabilty of the code.
I don't like using everything if it's new, you need to think about it if it's worth or not.
Hi Erhan
PHP and JavaScript are different and I don't think only just because you want to use arrow functions you would switch to JavaScript.
On the opposite hand, I think arrow functions increase the readability.
Well, If you work on your own project alone it can be ok but real world isn't like that. You can work with a team on a big project and it can be really really messy with arrow function.
I know it because I worked on a big javascript project with a big team and arrow function makes it really mess in my opinion.
Right now my php team doesn't allow using arrow function and I'm happy about it.
I respect your opinion but really disagree about being messy since arrow functions are made to make code more clear if your function is not that much complicated. If you wanted to use a global variable in PHP you should
GLOBAL
or$_GLOBAL
which is not needed in arrow functions.For functions that perform simple operations, I'll rather a bunch of arrow functions instead.
IMO, It makes such functions more readable 😁
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.
Yes, it would have been awesome. Maybe in the later version, they will add such a feature.
It would be helpful if you can add the PHP version from which each feature is available. I think most features you mentioned only available in PHP 7.4
New in 7.4 are the arrow functions and the
$foo ??= 'bar;
assignment. 7.2 brought class-based type hinting and return types, and everything else was included in 7.0 - including$too = $foo ?? 'bar';
and scalar type hinting.I love that a
✨Spaceship operator 🚀
exists.
Nice post, thanks!
Doesn't Laravel automatically trim the values of the request?
For some reason sometimes there is an inconsistency. That's why I added another layer or triming. LOL
so cool
Muy Bueno... Gracias.
Gracias para leer mi articulo. xD
Don't forget you can also assign values in the assignment part:
$type = ($age >= 18) ? 'adult' : 'no adult';
is the same as
($age >= 18) ? $type = 'adult' : $type = 'no adult';
The single question that i have, cuz i m lazy at the moment, is this a 7.x feature? Or is it possible on 5.6.x , too?
Hi
I believe they are 7.x features.
$base_url = $url ? $url : 'localhost';
shouldn't that be
$base_url === $url ? $url : 'localhost';
otherwise the condition will always be true because you assign a variable..
Hi Dan
Not it is not a condition, it is an assignment statement.