What are the worst parts of PHP?

9 points by justinzollars ↗ HN
Would you ever consider a job in PHP? Are the worst parts of PHP blockers for you? Tell me about your experiences!

19 comments

[ 5.0 ms ] story [ 60.5 ms ] thread
Worked on PHP on-and-off for more than 15 years. Jobs in PHP can sometimes pay well, but the PHP labor market is fairly saturated, so you're more likely getting underpaid than well-paid.

Here are some of the reasons I don't use PHP anymore:

1. Code bases often written by near-amateurs, so almost always a headache to work on

2. Terrible type system (and unpredictable type coercion) mean that the code has to be written with great discipline or it's going to be buggy

3. Inconsistent signatures of built-in classes/methods/functions means that it's almost impossible to remember anything, so you need to consult documentation (or inline completion) constantly

4. Very generally, a community that likes magic (see: Laravel) -- ease/speed is prioritized over correctness/explicitness, which means maintaining large PHP projects is often a nightmare

Thanks for the info! I may have an offer and I want to make sure I am aware of my unknowns.
Currently working as a full stack dev with PHP on the backend. Every language will have its pros and cons. If there was one language to rule them all then everyone would use it. Point is you should instead focus on how the company uses the language. Do they have standards, tests, deployment process, etc..? Every language can have projects that are a nightmare or a pleasure to work with. It really all comes down to the company.

Ask to see a code sample if possible.

nice points. Def know there is not a language to rule them all. I'm a ruby fan - its "good enough" but def full of faults. I just wanted know the pros and cons of PHP so I properly weigh my options.
Irony, thy name is PHP. Your name means "hypertext pre-processor" and was conceptualized first and foremost to be a web dev language. But you're now often being turned down in the web dev world in favor of general-purpose languages!
The web is used radically differently now than it was 22 years ago in 1995. Also, PHP wasn't designed to be the platform for large code bases maintained by multiple people. It wasn't really designed at all, as its creators have said publicly.
What are you mostly working with these days? I really need to branch out from PHP...
If I could choose anything, I'd go with Rust, Clojure, or F#. I'm currently working with C#/.NET and enjoy C# well enough, but mostly hate .NET.

I had a fantastic experience writing a thoroughly-typed, functional-style REST API using TypeScript -> Node recently, and I'd highly recommend that for someone who is practically-minded.

Are we talking about modern PHP or pre-PHP7?
Lets say both, I'd like to hear your perspective.
In many ways OO PHP is starting to look a lot like Java. Verbose and overarchitected code. It was a good templating language for C modules, not so good when you try to shoehorn it into solving every problem that you have.
the parts after "<?php"

Seriously though, I would think long and hard and be unlikely to take a job requiring more than a trivial amount of php. For me its tough to structure well, the stdlib is inconsistent so it means constantly having to look at the documentation, etc.

>Would you ever consider a job in PHP?

Heh. Most of the programming work I get is with PHP. I wish I could find work not in PHP. I'm still paying off a degree for building business applications in C# - and trying not to forget C# because I never use it. I can't seem to get a chance to forget PHP.

To me, the worst parts of PHP are, first, that the language was designed and intended to be used the way Wordpress (and many small hacky sites) use it - with PHP, HTML, Javascript and CSS all mixed together.

And second, that PHP isn't aware of context - it doesn't treat XML as objects (the way Hack does with XHP) and doesn't escape variables by default. One either has to manually escape every instance of every variable with a function whose name is too damn long (htmlspecialchars) or use a framework which does that for you.

The second point entirely undermines the purpose of PHP, and turns the first into an utter minefield.

Automatic escaping would not work anyways, you need to escape for the appropriate context (HTML, JS, CSS, JSON, XML...).

You don't have to use a framework, just use one of the many composer packages available like Twig for example...

(comment deleted)
I am working on a nice PHP 7.1 codebase where we just started with DDD. It's awesome.

Yeah there is quite a bit of legacy code still there (the application is over a decade old), but all the new OOP code is nice to work with and we are getting rid of the old one slowly over time.