Hacker News new | ask | show | jobs
by Jach 12 days ago
Yeah, the most shallow "PHP bad" comments are pretty annoying, but they sometimes have a point, and there are always new programmers who don't know any history. One of the bug fixes I saw today was for an issue that's been around for 20 years and is another consequence of PHP's decision (IMO a bad one) to have a unified "stream wrapper" API such that functions named, for example, file_get_contents(), can be passed a URL rather than a file. If that URL was httpS or HTTPS (i.e. an uppercase S), then the bug now fixed was that PHP would ignore TLS and initially connect over port 80 and make the initial request (along with sending whatever else) over plaintext. It could also successfully follow a redirect to actual https but hide that it leaked data in the initial request. This is just such a PHP thing. I've at times acted the apologist for PHP, it was my first language over 20 years ago so I'll always have some fondness for it, but in my heart I do think it fundamentally sucks and can't be evolved to stop sucking.

The last time I did any professional work in PHP was probably 2012, though. Since then I've only maintained a couple things I originally made myself, and on rare occasions have written a standalone script or two (I think the last one was about 3 years ago) and it still makes me happy that I can just rsync things up to my site. Thankfully the maintenance work has been very minimal, but in contrast I've not been excited about any PHP changes since the early 5 days, and my upgrades from 5 to 7 to 8 were mostly just going "huh" (though sometimes "Eh? wtf") at the new features while being wary of breaking changes (the upgrade guides over the years have been helpful and there haven't been many breaking changes). When I look at modern PHP, it's structured quite differently to how my old waiting-to-be-rewritten maintenance sites are, and I don't like it, I just think it's become a worse Java, and most professional deployments seem to use a big framework and have a whole deployment workflow (vs. just copying a few files) so again why not just use a Java workflow that'll be at worst equally cumbersome but without all the PHP nonsense. On new language features specifically, I stopped getting excited over those in any language once I found my way to Lisp, where if you want some language feature, you don't have to wait for some committee to add it, you can just add it (or someone else has already added it, or it's always been there since before I was born). It's nice when other languages play catch-up, sure (though sometimes they implement something worse than not having it at all), but I can't ever muster excitement...

1 comments

> This is just such a PHP thing.

What makes it a PHP thing? To me it sounds like a bug that could occur in any library, but I neither have as much experience with PHP nor context on the bug.

Sure it's the type of bug that could technically occur in any library, being case sensitive when you should have been case insensitive (or done something else not reliant on string case at all), and on its own not that severe, but the whole thing has so much PHP character to it when you take it from the abstract "character case issues happen" to the specific "connections won't use TLS unless the 's' in 'https' is lowercase" (wat). The set of details shape the character. If the URL's host responded over port 80 with a redirect to https, that would work, but you already sent data in the clear with the connection subject to mitm etc. and you get no notice of that. If you tried to be smart and specify an explicit port number, but still had an uppercase S, in the normal case the connection would at least fail and you'd learn about it because PHP wouldn't follow the expected TLS protocol the remote host expects on that port (after already transmitting stuff in the clear). And of course this is all in a language context where you're passing URLs as strings to functions some of which are suggestively named as operating on files, but hey maybe you're passing a stream context so it's a bit more clear you're not doing something with just simple local files. Anything involving a network request can fail in a variety of ways, and oh boy does PHP have a variety of ways of surfacing or not surfacing issues, or trying to continue forward regardless, maybe via trivial implicit type conversions, or via things like following redirects.

I think this article does well at highlighting a lot of the PHP character: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ It wasn't a perfect set of criticisms even when it came out (and there were a lot of apologetics in discussions about it) and a bunch of things have changed since 2012, but the character hasn't. Maybe the tersest simplification is just the quote "PHP is a community of amateurs", though I don't think that fully captures it all, and in any case isn't necessarily bad and in many ways can be quite beautiful. But it's part of what gives the whole ecosystem its character and flavor for how things are built with it (and what bugs that surface look like) that other ecosystems don't share, and that character is what I'm getting at with how this particular bug seems like such a PHP thing. Like, spend some time reading up on ridiculous WordPress bugs, some even from this year, and you'll see similar expressions of character. That's not to say you can't find ridiculous bugs in, say, the Java ecosystem, but I think you won't find them as frequently, and when you do you'll more likely see an expression of their separate character as stemming from a bias towards over-abstraction / over-engineering rather than a feeling of amateur hour code slinging.