Hacker News new | ask | show | jobs
by RutZap 2972 days ago
> It’s not prejudice or signaling, it’s objectively deficient in ways that haven’t been acceptable in decades.

I don't want to start a useless debate or anything like that, so don't take this in the wrong way, but I am genuinely curious of what specific problems you see in PHP and what are the specific issues with the language.

I can't think of many things that are so bad with it, except the inconsistency in function naming and parameter orders (stuff like `str_pos`, `substr`) and a relatively unreliable SoapClient implementation; I am genuinely interested in seeing what other people think are deficiencies in PHP.

Again, I have to stress I am not being defensive nor offensive, I am just curious on other perspectives in regards to the shortcomings of PHP.

4 comments

I am genuinely curious of what specific problems you see in PHP and what are the specific issues with the language.

There are so, so many. Here are some good references:

http://phpsadness.com/

https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

Disclaimer: I earn my income from a project largely written in PHP.

I'd like to second that! I haven't used PHP much since version 5, and while I'm inclined to believe that there's only so much that can be done to 'fix' a language that isn't particularly good, I'd love to hear how things have changed for the better, but also what problems still exist.

Much of my own work has been javascript, and I could probably write a similar comment about how much has improved and yet how much is still fundamentally unpleasant because of the initial design (and the need for backwards compatibility). Of course, enough has probably been said about that...

The one shortcoming that I ran up against repeatedly is the implicit initialization of variables to be a string containing the variable name. It turns typos from compile or run time errors into subtle bugs.
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.)