Hacker News new | ask | show | jobs
by RutZap 2982 days ago
I have been using PHP professionally for 7 years now and I absolutely love it. The community grew up from the old days when I started playing with it (almost 15 years ago). There are incredible pieces of software built with it, and nowadays the language is unrecognisable from the state it was in when it gained the bad reputation. i think Symfony 4 is a wonderful framework and it allows us to use PHP to build things that most would think it's impossible in the language of spaghetti code.

Yes, there are still a lot o people out there that hack some very questionable code together in PHP but we shouldn't dismiss it like this. I've tried multiple languages (C#, Java, javascript) and I have to say PHP is my favourite so far (you guys can comment on this as much as you like, I still like it a lot).

It's disheartening to hear that in a hackathon people got "bullied" for using a programming language. You would never pick upon a mechanic for using a screwdriver instead of a chisel or something similar, as long as he can achieve the same thing.

Also, I can't help to notice a trend of ..."brogramming", where if you don't use the newest and coolest tech you're treated as an outcast, bullied and made fun of; it's quite sad if you ask me.

6 comments

> I've tried multiple languages (C#, Java, javascript) and I have to say PHP is my favourite so far

All programming languages have short comings. The once you mention here even more so I believe :)

Picking a favorite out of a very small subset is mainly personal choice. If you are happy with the toolset and the programs you create, I think you made the right call.

> "brogramming", where if you don't use the newest and coolest tech you're treated as an outcast, bullied and made fun of

I see this too, but I believe it's more specific to web development. A lot of people program C and they are generally not bullied for that.

> nowadays the language is unrecognisable from the state it was in when it gained the bad reputation

I used it then (3.x, 4.x) and I recognize many of the terrible warts are still front and center.

PHP isn’t bad because it’s not new and shiny, it’s bad because it does opaque and wrong things and demands a user of the language know all sorts of inconsistent PHP-specific nonsense that does not benefit the language authors, the language users, or serve the solving of the problem of the language user. It’s not prejudice or signaling, it’s objectively deficient in ways that haven’t been acceptable in decades.

And then we have javascript, somehow people seem to think that is ok.

I much prefer PHP, also the warts are serverside which makes a huge difference.

> 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.

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.)

PHP has shortcomings, for sure. And I'd probably scorn at people for using it for production-grade, "serious" tasks, and I'd be sure to find some security issues within their code (it's not just php, it's the libraries AND the coding style it promotes).

But for an hackaton? 36 hours to get something done? It may be totally be the best tool for the job.

If the only goal is really gone in 36 hours the hackathons are at fault. I would absolutely hope to walk away with something of value for my 36 hours, and not a pile of throw-away code.

It has been a long time since "throw away the prototype" also meant switch languages, databases, production OSes, version control systems, and library code. Modern languages are flexible enough to let you prototype rapidly with sturdy languages, front end and back.

Experience comes in different levels. There's professional experience, for example knowing it is stupid to use a certain algorithm to solve a certain problem and then there's life experience, for example recognizing how pitiful language bashing is.
If it works, and you can write code which meets the spec quickly - then who cares?

I fell into this exact trap - Moved my org from PHP to what was "New and Shiny" -- and while it worked out, our prototyping / proof of concept speed isn't nearly as fast as it was with PHP.

Completely agree with you. In the last 5 years I wrote a lot of Javascript code in Node. For sure I can say that there is no great framework that give you the "completeness" that Laravel, Symfony or CakePHP give you.