6 ms·
Modern PHP is much better than the old one. One feature I miss from Kotlin are Infix-Functions: https://kotlinlang.org/docs/reference/functions.html#infix-notat
by thibran 8y ago
Modern PHP is much better than the old one. One feature I miss from Kotlin are Infix-Functions: https://kotlinlang.org/docs/reference/functions.html#infix-notation https://kotlinlang.org/docs/reference/functions.html#infix-n...
Even the newest PHP feels somewhat dated, Infix-Functions could reduce a lot of typing by making library and custom wrapper code – which almost always exists – resemble more.
function foo(String $s) {...}
// current function call syntax
foo('hiho');
// just syntactic sugar - below code is the same as above
function String.foo(String $s) {...}
'hiho'->foo();
- Something1234 8y agoWhy is this a useful syntactic sugar? EDIT: I'm dumb. The syntactic sugar is just operator overloading. The better question is why would you ever give that to a PHP developer? I've been digging through some of it, and it's just annoying to untangle some of the code people write, as compared to other languages.
- thibran 8y agoFor example you can't just write [1, 2, 3]->map(...) in PHP. Right now the best is to use something like Laravel's collect, e.g. collect([1, 2, 3])->map(...). Oftentimes all you want is to add one method to an object. Right now you would have to sub-class it or write an ugly wrapper function. Infix-Functions are one way to "extend" functionality without messing with inheritance – with other words, you can easier express what you mean with less code in an consistent way. In Android dev, Kotlin and Infix-Functions are quite popular. Too often in PHP you have to write some_function($object). The other thing is that PHP has a lot of strange function names and Infix-Functions could help to give the language designers a second chance to come up with better names, even if the Infix-Functions just call the existing code.
- Something1234 8y agoI would be fan of adding some kind of in-place map as a method on an array to php, but other that that I don't see much benefit to it.