Why People Think PHP Sucks (2014)
audero.it
audero.it
https://en.wikiquote.org/wiki/Rasmus_Lerdorf
"PHP is about as exciting as your toothbrush. You use it every day, it does the job, it is a simple tool, so what? Who would want to read about toothbrushes?"
"I'm not a real programmer. I throw together things until it works then I move on. The real programmers will say "Yeah it works but you're leaking memory everywhere. Perhaps we should fix that." I’ll just restart Apache every 10 requests."
"PHP 8 is significantly better because it contains a lot less of my code."
To put this quote in context, over the last decade, a lot of legacy PHP features were deprecated and removed. Some in the community were opposed, and wanted Rasmus Ledorf to ape Linus Torvalds and reject the changes. His comment here was him explicitly saying he wasn't precious about the original design, and welcomed the changes.
The most annoying thing about PHP criticisms is people wheeling out these hackneyed old articles and quotes that don't say anything at all.
PHP is a joke language. It's most major usage is a joke company. Making jokes about it is apt.
EDIT:
Including your PHP WordPress blog. Curious.
And if someone calls PHP a joke, but then personally chooses it for themselves, there is certainly some inconsistency there.
It's good to see humorous developers love spreading jokes.
I use PHP, whenever I write server code. My main bailiwick is native Apple software (Swift, usually UIKit/WatchKit/AppKit).
PHP works great. Very fast, easy to provision, and has a massive stdlib, with lots of industry best practices, built in.
That said, I don't like writing in the language, and try to keep my incursions into the backend, as brief as possible (I just wrote a new server, to replace one written in Python/Django that had fallen down -took me about two weeks).
I am quite sure that there's a ton of folks that are far better on the server end, than I am (even in PHP). I don't care. They aren't stepping up to the bat for me, so I have to do it, myself.
But PHP has always delivered, and delivery is important to me. I knew a manager, once, that said "Shipping is the most important feature of the product!".
[1] - https://news.ycombinator.com/item?id=33613037
[2] - https://news.ycombinator.com/item?id=22345150#22345721
[3] - https://levels.io/how-i-build-my-minimum-viable-products/
> Shipping is a feature. A really important feature. Your product must have it.
[1] - https://www.joelonsoftware.com/2009/09/23/the-duct-tape-prog... edit - added more context
I get the feeling that a lot of HN folks don't like him, though, which puzzles me.
Same with Steve McConnell.
Personally, I credit much of my career to advice from Spolsky and McConnell.
People thought php sucked back then because it was obviously trash.
TFA isn't even touching on any of the very real unmitigated embarrassing failures in the decade of php growth leading up to 2014.
At one point I rolled out a php cgi update that broke something like 10% of customer scripts which upon investigation was due to the scripts containing mismatched curly braces. Pre-update, they worked well enough for the customers to have the impression that nothing was wrong. Post-update, all the sudden the php interpreter noticed these scripts didn't even have correctly enclosed code blocks. There'd be an open curly brace with no closing brace, or vice versa. It was lots of jibberish, and earlier versions of php did not care and if the random results were consistent with expectations, you carried on.
The fact that there was a post-1.0 php interpreter in widespread production use silently accepting such syntactically incorrect code clearly demonstrated to those stuck responsible for keeping this stuff ~working, while rolling out seemingly endless urgent security fixes, that php was a raging dumpster fire pushed by a clown car.
The criticisms I would say are both still true of PHP, and aren't true of all languages:
* The PSR-4 pattern of "one class per file" encourages a lot of files.
* There's no concept of a module, where classes and methods can be public within that module, but private outside of it. This makes it hard to expose an interface.
* It's pretty verbose, with lots of boilerplate, brackets, and semi-colons.
* Installing extensions makes it difficult to configure environments.
All that being said, PHP would still be my go-to language for doing a low-traffic application doing mostly CRUD. It's a stable and reliable language, performant for many use cases, with some fabulous frameworks and libraries.
We recently got constructor promotion which has been really nice https://stitcher.io/blog/constructor-promotion-in-php-8
> Installing extensions makes it difficult to configure environments.
At least the way I do it, required extensions are just 1 line in a Dockerfile.
A typical PHP file now includes:
<?php
declare(strict_types=1);
namespace App\Something;
use App\Services\Bar;
final class Foo
{
public function __construct(private readonly Bar $bar) {}
public function doSomething(): string
{
return $this->bar->baz();
}
}
And I end up with a lot of PHP files that look very simlar. I'd love some defaults here.* strict types
* namespaces to be autocalculated (since PSR-4 means it has to be in that namespace anyway)
* private, final and readonly both default to true
* The opening PHP tag
* Relative namespace
* Plus all those brackets and words that duplicate information. If it has brackets, it's a function. An empty function body doesn't need curly brackets.
I recognise this is a backwards-compatbility thing, so it's not as easy as "just do it". But I'd love a PHP file that looked lke:
class Bar
{
__construct(Services\Baz $baz)
public doSomething(): string
{
return $this->baz->bar();
}
}
But again, this is me waxing lyrical. I still prefer PHP to Python, but I do like Python's expressiveness.I had this error once in 2005. Found the solution quickly. Never had it again.
If you use PHP in a clean way, you won’t get in touch with most of the quirks he mentioned.
I don't know if this is still true, but the impression I got at the time was that PHP is constantly trying to catch up with more advanced languages. There was no case I could point to and say "PHP is the best choice for this".
If I want to write a highly concurrent distributed system I'll reach for Elixir/OTP. If I want high performance, I'll reach for C or Rust. If I'm working on a data science project, I'll reach for Python or R. When is PHP the language to go to?
(Next time I try web CRUD, I'll try it in Haskell. It seems to have let the more traditional languages behind.)
You've got Ruby on Rails and Elixir/Phoenix which both have an enjoyable developer experience and a well designed language.
There's JavaScript & Node.js where the language is a bit of a mess but the ecosystem is huge. Plus the same language can be used on the frontend and backend.
Python is extremely popular with Django, FastAPI, and Flask.
C# is also extremely popular with ASP.NET Core, although I've never used it.
I'm open to discuss pros and cons but over the value it might bring, or not, to an organization and its natural limitations or features.
private int|float $foo;
TypeScript and Python are others. There's really nothing that bad about PHP compared to other scripting languages. My biggest complaint was the inconsistency of naming/parameters of standard functions. I used the Yii Framework for a project and it was much better than expected and the caching and query optimization features were outstanding.The fact that some big name companies use it doesn't change that perception (especially when one examines the claim more deeply and realizes their use of PHP is surface-level at best anyway).
In real life business the productivity, security, ecosystem and guarantees of a battle proven tool matters *a lot*.
Not sure what alternative you're proposing here and I don't think this is the case, but I've seen already too many times the "Django/Laravel/Rails are bad so let's write our own awesome framework" and let's not get started on how that goes 99.99% of the times because you can already imagine it.
Also:
> For sure you can write clean, maintainable code in Laravel
This (and the opposite) applies to every single language and framework. In my experience it is more an attribute of the developer than of the tool/language/framework.
The rest is minor crap which doesn't really affect you once you're at your second project. I have a plethora of similar small problems in python (even if it's arguably better designed) and I see people with little familiarity with JS facing a bunch of small problems.
I think most of it is due to the OSS nature of languages and the lack of care for developers' experience. Too many democratic committees circling around issues and the lack of a company making a sensible choice because it makes business sense. An attitude of leaving basic functionalities to the OSS community to maintain for free in perpetuity - or until the dependencies blow up and everybody need to fix them.
Personally I'd love to have a paid programming language with a single creator's viewpoint. Elm got close but then decided to sabotage third party contributions in a way that ruined developer experience.
What? It at least much stronger typing than JS. Having a separate concatenation operator already helps a lot.
Or do you mean, like static typing? Here PHP has the best gradual typing story of all the dynamic backend languages.
TS is super complex and needs an additional compile step. Python type declarations are a lie and can not be trusted as they are not enforced in any way by the language and different type checker will give you different results.
PHP enforces types at runtime and static type checkers are fast and reliable. Dynamic productivity with static safety when needed.
(FWIW, one thing Facebook did have in it's favor is that it got pretty disciplined about what parts of the language to use or not use early on (e.g. no extract), which IMO made a large difference compared to typical php codebases back then.)
That evaluates to true if you're using PHP prior to v8.0.0. A good example of why you almost always want to use strict comparisons (===).
Php7 (and especially 8) seems to be a nice language, but man, the php hate was really warranted at the time.
You can't really blame a language for the fact that some people wrote bad code in it. By that metric all languages are bad.
The valid ones are mostly nitpicks. Some standard library functions have inconsistent naming/argument order/poorly designed/multiple functions that do the same thing. Hard to change for back compat reasons, but you can simply not use those functions.
The ternary operator being left associative is the only truely wtf php design choice on the list imo.
The inexistence of footguns or statically enforced good practices are things we would usually praise a language for. So why should PHP not take the blame for how easy it is, to write atrocious code?
https://wiki.php.net/rfc/ternary_associativity
it now requires parenthesis, and will be transitioned to being right associative