Hacker News new | ask | show | jobs
by adimitrov 2983 days ago
It's commonly known that PHP sucks[0], there's really not much to say about it.

Off the top of my head, the awfully inconsistent "standard library" (and kitchen sink) is a true nightmare (array_map vs. array_walk, wtf?) the absolutely hamfisted and counterintuitive autocasting (and no way to do strict comparisons besides equality), the disaster that is its "type system", leaking implementation details of the parser into (language) user space (T_PAAMAYIM_NEKUDOTAYIM anyone?) the absolutely intransparent difference between built-in functions, keywords, expressions, etc (can I use empty() here, or was did I have to use is_null, or any of the other half a dozen ways to express "does this exist?"), the list goes on…

PHP's design is anti-intellectual (on purpose) [1] and so PHP didn't even have an AST until version 7. It just emitted opcodes after lexing. Yes. It truly, amazingly did that, I couldn't believe it either, but there you go. This lead (directly or indirectly) to many faults in the language. It's also the core reason why PHP 7 is about 2× faster than PHP 5.x. Who knew you could optimize a parse tree before executing it?

If you want to find faults with any language, you can. With PHP, you can find more faults, and more easily. But the real problem is that those faults do kill productivity. I use PHP in my day job, but recently we've moved to doing more client-side programming in React. I get to use flow's type system which isn't perfect, but believe me, it's a breath of fresh air after coming from PHP. I'm not a fan of the JS ecosystem, but it's still better than PHP.

The community has made huge strides with PHP 7, and it's finally getting into some OK shape. The reason PHP is huge is because it made the right decisions at the right time. The threading model is dead-simple (there just isn't one) and requests are automatically isolated at a process level. No recompilation, no fuss (but then you forget to flush your opcache after deploying to production and everything explodes…) It's easy to get started with, and it's easy to make a simple thing with. It may even be the "correct" choice for a Hackaton. It most certainly is, if PHP is the language you're most comfortable with.

I'm too old to lead language flame wars. You can do great stuff with it, as you can with almost anything. It's not impossible to write good PHP code, it's very possible! But not because of PHP itself. PHP is an objectively bad language

Given the choice, I'd rather code in Java, or C#, or even TypeScript+Node.js. But I'm not, so I code PHP every day, and it's not like that's the worst thing in the world. It just feels like I'm fighting the language, instead of the language helping me.

[0] https://duckduckgo.com/?q=php+sucks

[1] "I was really, really bad at writing parsers. I still am really bad at writing parsers. We have things like protected properties. We have abstract methods. We have all this stuff that your computer science teacher told you you should be using. I don't care about this crap at all. " ~ Rasmus Lerdorf (yeah, sure, taken out of context, but the point still stands, and there is no dearth of interviews and quotes of his documenting the same general attitude.)