by lexicality · 2y ago · 0 comments
Going from a language with a well organised stdlib with consistent syntax to php is not fun.
Sure, it has a lot of nice features now, and some of the footguns have been removed, but the core language is still there and it's still a mishmash with a bunch of hidden landmines.
As someone who spent many years developing in (and defending) PHP, I agree with everything you just said.
Nowadays, I'd rather reach for Crystal, Go, or Rust for back-end application development, and Python or Typescript (!) for automation scripts.
This is one of the weakest, "not happening in reality" issue of PHP though. It's the most obvious, and the one who don't use php but glance at it point. But in the real world, any editor you use not only show it but also show a type error if you made a mistake, on top of that after a few hours you know which is which (yes strpos and in_array have an opposite haystack/needle, but each always use the same, once you use them more than 5 times you remember the same way you remember to check for 0 on strpos).
There are still flaws in the php world, but the one most commonly pointed out are always sounding funny to me because they're flaws if you show an exemple in a conversation but that you don't actually hit when coding.
Good languages don't make you memorize exceptions.
Praytell, how does your editor show you a type error when both `needle` and `haystack` are strings?
It's hard to trust a stranger from internet claiming something, but we are in IT so it should be relatively trivial to prove your claims, right?
And that will return true, because you forgot the third "strict" parameter. This is really something strict_types could/should have fixed, but it doesn't.
You can have code reviews and static analysers and all of that to catch this, but it's definitely a landmine. I've seen some pretty serious CVEs that were fixed just by adding that last parameter to some in_array() call.
Was that everything? You basically state there's a problem because you didn't use the function correctly and language didn't fall head over heels to stop you from doing silly things due to slopiness?
P.I.C.N.I.C.
Please provide examples in other languages (eg rust) so that I can answer your original question properly and to your satisfaction
It would easily catch this. https://phpstan.org/r/a827ff45-4ee2-4bee-8ae0-935832e627b3
I hate Rollercoasters, I hate surprises and strong emotions. So if you ask me how Disneyworld is, I'll tell you it sucked for me. But maybe you are onto that, so you shouldn't trust me.
Back yo PHP I've used it for super fast tiny dynamic websites, and it works wonders. I wouldn't do an online exchange with it though.