PHP: a fractal of bad design (illustrated)
PHP string functions naming convention
The PHP iceberg
Recruiter: We use a modern tech stack. The stack:
Explaining PHP to a new developer
PHP is like a kitchen where every drawer has knives, but they're all slightly different sizes and some are actually spoons labeled as knives.
Why does sorting an array modify it in place but array_map returns a new one? Isn't that inconsistent?
Welcome to PHP, where consistency is treated as a suggestion rather than a principle.
+1 more replies...
How PHP handles types
WordPress developers explaining why PHP is fine
PHP: The Good Parts
PHP type coercion will haunt your dreams
In PHP: "0" == false, "" == false, BUT "0" != "". The transitive property called — it wants its dignity back.
Just use === everywhere! Problem solved!
"Just remember to always use the special operator that does what the normal operator should do by default" is not the flex you think it is.
The PHP version of 'it works on my machine'
In PHP, 'it works on my machine' has a special variant: 'it works on this specific PHP version with these specific extensions compiled with these specific flags on this specific OS.'
I once spent a week debugging why code worked in development but not production. Turns out the production server had a different locale setting which changed how string comparison worked. IN PHP.
This is literally why Docker was invented.
When someone says PHP is a good language
PHP error handling be like
PHP's greatest feature is that it makes you appreciate other languages
After 5 years of PHP, I switched to Python. The first time I saw consistent function naming I genuinely teared up.
Try Rust. After PHP, the compiler yelling at you actually feels like love.
I've been writing PHP since PHP 4. Every year someone says it's dead. Every year I'm still employed. The real joke is on the haters paying more rent than me.
PHP developer fixing a bug
Why does PHP have 67 different string functions with inconsistent naming?
Why does PHP have str_replace, strpos, substr, str_pad, str_repeat... but then strlen, strcmp, strstr? WHO DECIDED THIS?
Fun fact: the naming convention was based on which C function it was wrapping. Consistency was never the goal. Shipping was the goal.
The real fun is when you discover that array_key_exists() and in_array() have their needle/haystack arguments in OPPOSITE ORDERS.
+1 more replies...
PHP date formatting is a war crime
PHP date format: 'Y-m-d H:i:s'. Y for 4-digit year, m for month, d for day, H for 24h hour, i for minutes (???), s for seconds. Why is minutes 'i'? Because 'm' was taken by month. Galaxy brain.
To be fair, JavaScript's Date object is also a mess. But at least we know it's a mess. PHP acts like this is normal.
My favorite part is that 'D' gives you 'Mon', 'Tue', etc. but 'l' (lowercase L) gives you 'Monday', 'Tuesday'. The letter l. For the word that starts with the day name. Sure.
PHP == JavaScript in terms of type coercion chaos
PHP: the language where everything is a footgun
PHP is the only language where I've seen a function called mysql_real_escape_string. Because apparently mysql_escape_string wasn't escaping things... for real.
And then they deprecated both in favor of prepared statements, which they should have done from the start. Decades of SQL injection vulnerabilities later.
Don't forget addslashes(). Three different ways to incorrectly prevent SQL injection before someone thought 'maybe we should just separate the query from the data.'
PHP elephant looking at the chaos
The PHP elephant in the room
Everyone on Twitter: 'PHP is dead.' Meanwhile, 77% of websites run PHP. WordPress alone is 43% of the web. PHP isn't dead, it's the cockroach of programming languages.
Something being widely used doesn't make it good. COBOL is still running banks. That's not an endorsement.
Fair, but cockroaches have outlived the dinosaurs. I know where I'm placing my bets.
PHP: A fractal of bad design
"(And strictly speaking, Facebook isn’t written in PHP; it’s written in a C++ macro language with a striking resemblance.)" I'm a Facebook engineer who works on the HipHop compiler and HipHop virtual machine. It's in PHP, absolutely full stop. It's amazing how much the fact that g++ is involved somewhere in the toolchain confuses people in this matter. C++ is just an intermediate representation; the source language really is warts-and-all PHP.
I'm going to be unfair and quote just two words from the article: > empowered amateur PHP is a gateway drug to web development. And that's awesome. With almost every other popular web development language I've heard of[1], there's this grey area between "my app works on my local machine" and "my app works on the server" that is really hard to grok as a beginner. There's a reason entire businesses are built on the idea of making this easy. With PHP? You get an apache box with PHP, you put
Meh, I've written a lot of PHP code. I also work in Ruby and Python. All three have problems, but I like all three. With PHP, you have to develop a coding style that naturally avoids PHP's weird areas. It's not really that hard to avoid the mines, but you do have to be aware of them. In exchange, you get a scalable web server and a language that requires minimal babysitting. Instead of automatically throwing a 500 on a random, unimportant, uncaught exception, PHP makes a best effort, and most
+3 more replies...
Why Developers Hate PHP
> Most developers who hate PHP hate it out of elitism or ignorance. Either way it’s dumb. You have to choose a technology based on what you need. PHP is highly useful and powerful in many scenarios. And taking it out of the equation just because of its reputation is not a good idea. When I conduct hiring interviews, one of the questions I like to ask regardless of the language for the position, is the developer opinion on PHP. It's not uncommon for some to start massive rant based on outdated
I think there's something people miss when looking at PHP as a system - the fact that it's a collection of hot swappable logic modules (pages) PHP pages themselves can download packages of additional PHP pages and extend functionality as the website runs. For example the user can install a message board from the UI in WordPress, and PHP files themselves will download additional PHP files needed for a message board, and boom your site now has a message board - no recompile, install, or deploy.
There was a tech talk I saw on Youtube a few years ago that I really liked that argued that Facebook succeeded because of PHP, not despite it. IIRC, the main argument was that despite its flaws, PHP has one killer feature, which is that it lets you have really tight iteration loops for web development. This made developing in PHP extremely productive. I searched around for the video, but couldn't find it.
+2 more replies...
Moving from PHP to C saved my web startup.
So it really wasn't PHP but Apache right? In an hour you could have switched out your front end server to Nginx and had it serve responses from Memcached and then keep the Apache/PHP backend and change it to update Memcached on bid changes. Here are some links: http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-b... http://lserinol.blogspot.com/2009/03/speeding-up-your-nginx-...
The more generalized takeaway from this is that you shouldn't use a heavyweight listener to handle polling (or websockets in the near future) if you can avoid it. PHP was the culprit here, but I can't help but think you'd have had the same problem if you were trying to do the same thing with RoR, any Java app server, or any of the Python frameworks. Likewise, node.js or Twisted probably would have been an equally effective replacement.
Good for you! I read all of the other guys asking, "but why didn't you do this? ..." I myself am a throwback from the C/C++ days and I frequently re-write stuff in C. That's how it's supposed to be done. Write as much as you can as fast as you can up-front, then optimize your bottlenecks using more efficient methods. I'm happy that C improved your situation that drastically. I agree that the overhead of lighttpd, then apache, then php might have been the real killer in your situation, and
+1 more replies...
Ask HN: Why has nobody built a better Wordpress?
Wordpress is terrible, but none of the ways in which it's terrible matter. From the point of view of the user, Wordpress is incredibly simple and intuitive. Don't underestimate how important it is for the average user to never see a terminal, and rarely if ever see the source code, for the application to feel comfortable to people most familiar with Windows applications and web forms. Anything more technical than that is intimidating. Most people who use Wordpress aren't programmers, don't wan
This is my first HN comment - I must be the only WP developer who reads Hacker News or something. Let me preface this by saying I'm not going to be repeating what's already been said about non-technical user friendliness. WordPress was my gateway in 2008-9 to web development. back when I was still a graphic design student. I started off hacking away at themes with my extremely limited HTML / CSS / PHP knowledge back then. Shit, my Google-fu was't really even halfway decent then. Toda
> Wordpress is terrible That's open to debate. I have 3 websites running on Wordpress, I don't have the intent to use anything else. It's simple and comes with batteries attached, especially for people who aren't hacking the code themselves. The plugins/themes are a big plus and so is the community. In what way is it terrible? Have you used it enough? > CMS as a whole is bad No. CMSes serve a purpose and serve it well. Btw, TechCrunch, Fortune.com run on Wordpress too. > Why has no one
+3 more replies...
Why people hate PHP, a book from hell
TLDR; op blames awfull books that spread bad practices and then made PHP code ugly and insecure. I personally don't care about PHP. Now the PHP community is kinda funny. Basically there are the people that use PHP as poor man's java, that feel the need to write 50 design patterns per file, who hates the other part of the community, the one that couldn't care less about "software engineering best practices". So it's not much that people hate PHP, more like PHP developpers hate other PHP devel
I think PHPs big strength is the other point mentioned in the post: It enabled lots of people who are not really programmers to do some programming. Some of them developed into serious developers, some of them didn't. Being able to produce something slightly meaningful even without any skill is a big accomplishment, but it also means loads of erros, over estimated skill levels, security holes, unreadable code etc. The reason this doesn't happen to Haskel is that you become a computer scientist f
Most of my hate is not directed at PHP but rather the code of the projects I run across written in PHP. It's not uncommon for there to be random whitespace and code thrown everywhere with no heed to a sensible MVC or other software architectural pattern. I do occasionally run into well written and maintained software written in PHP and, while it's not my prefered language, it's quite readable and I can work with it. PHP does have it's issues but they are exacerbated by the general community th
+2 more replies...
We Don't Hate PHP
This is such a surface-level article. Most of the things listed as advantages exist in other languages as well. Here are some actual reasons to like PHP: 1. Java-like interfaces and classes and strict argument (and soon parameter) typing enforced at runtime 2. Autoloading and "lazy loading" of classes means defining bi-directional relationships between classes/types is painless (this can of course also make you shoot yourself in the foot, but I prefer that to dealing with circular import
Those all seem like features any modern programming language has. Nothing here particularly distinguishes PHP from the rest of the crowd. I don't think anyone is surprised by the fact that PHP has classes and some niche methods integrated in most standard libraries. I would like to go one further and say most other more modern programming languages do each of these better. It's always a good idea to look what is beyond the horizon.
I don’t hate PHP either. I just want to be able to get another job doing something interesting after I spend 18 months at your company. Otherwise I’ll be stuck in the public sector maintaining broken Deloitte unemployment portals, making 1/3rd of what junior coding academy developers make. Easy calculus.
+3 more replies...
“Sites like these give PHP a bad reputation”
What alarms me much more than the appearance of bad code quality is the fact that we have no direct way of checking what's actually going on under the hood and what impact it has on security. If there is one axiomatic requirement for the trustworthiness of a password manager, it's that it must be open source. That way people don't have to guess at the code quality from their use of file extensions. Lots of people seem to have a huge phobia of storing their passwords in the cloud and I have the f
I've been working on a reimplementation of the LastPass command line client lately and while I was also a bit surprised when I found out that the login URL was "https://lastpass.com/login.php" I didn't really think much of it. In the end the server side of things is really not critical since it only stores an encrypted version of the blob. Sure, it looks a bit sloppy, but if it works... The real weakness of lastpass is and always will be the clients, in particular those browser
Facebook was doing something similar (.php URL's). Should we avoid Facebook? Maybe. But for this reason? I was a PHP dev for nearly a decade and you can't possibly know the ways I hate it (unless you're a PHP dev too); but this is a very poor form of criticism.
Ask HN: Why are so many PHP projects moving to Node?
I wouldn't pay too much attention to what "the webdev industry is doing". That's how we ended up with MBs worth of javascript to display a simple website, not to mention the cpu required to render single page apps that won't even let you open a separate tab and constantly break. Most people in this industry are either junior devs that have no idea what they're doing, mid level devs that fall for the hype and don't like "boring" tech (battle tested, reliable) and end up using stuff that's not ev
Three major reasons. React, Typescript, and isomorphic/universal JS. The reasons for React's dominance is a separate topic, but if you're working with react, node becomes a natural fit for the backed because you can render the same components on the server or the client. Again, the reason for TypeScript's success is a separate topic, but node is the go-to backed if you intend to build with typescript. All things being equal in the interpreted scripting language world, typescript's type s
I think it’s the culture. The code quality of almost every PHP project I’ve seen is atrocious. I’m not saying every JS project is perfect (far from it), but amazingly well-written JS projects are ubiquitous. So when I ask myself “how much do I trust complete strangers on the internet?” the answer is “not much, but even less than that if it’s written in PHP.”
+2 more replies...
PHP: a fractal of bad design (2012)
There is one major reason why PHP is so popular: The step from HTML only to a slightly enhanced webpage with dynamic elements is easier than with any other language (JS included). Combine that with the simplicity of mod_apache (that is available on almost every web host) and it is the easiest way into programming. Create a mod_[ruby|python] that just evaluates ERB/Jinja templates and is as simple to integrate into apache and you might be able to do something good.
It's strange that, given how badly designed PHP really is, it's so surprisingly flexible that things like my PHP preprocessor can exist: https://news.ycombinator.com/item?id=7861616 I'm sure you could write a shorter, (maybe) faster, cleaner preprocessor for Python, Java or Erlang, but I'm not sure it would be a viable solution, there. With PHP, I got this 'mostly unused hash comments' thing readily available, like a low-hanging fruit. And then, there was token_get_all() - the sq
At least half of these things are either examples of good design or neutral. That said, there isn't a single language for which I wouldn't be able to produce a laundry list of "bad design" that's equally as long and disturbing as this one. Insulting PHP developers and their work is certainly not the best way to "hurt" people's "opinion of PHP." It's a great way to come off as a pompous asshole, however.
+2 more replies...
Why so much hate for PHP?
TL;DR: Because we used it. Like many people, many years ago I learned php. It was easy to deploy, and make simple dynamic websites. Many hosting services provided support for it. I was quite happy to use it for these things. Then in 2008 I interned at Facebook. At the time, there had not yet been any attempts to improve the language by Facebook itself. Using php in an actual codebase - real world software - made me realize just how terrible it was. I vowed to never use it again. I even present
A quick dive into any PHP-related topic on HN should yield significant answers. Part of the hatred comes from the fact that the way people know PHP is from 2005, when it was essentially one really long procedural program. It's not so much that people ignore the recent upgrade in tooling/modern language constructs so much as people aren't familiar that they exist. However, these is still a lot of vitrol for PHP. Because it is so easy to use, many people are able to pick it up without any pr
There are a lot of reasons already discussed, this one is especially famous: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de... PHP is not a exceptionally bad platform from a technical perspective, it usually gets the job done, is reliable, easy to operate and performant. But i guess the real reason why so many developers - including me - hate PHP is that plain PHP is pretty boring. It doesn't have opinions on anything and no exciting concepts or
+3 more replies...