I worked on a data pipeline that was a mountain of PHP scripts bolted together with Bash and it was such a breeze to maintain. Using Symfony ensures that every command is well documented and consistent in design and use.
Something I never appreciated about PHP until recently is that character encoding is so much more robust in PHP than other languages. We were forced to replace our pipeline with Python because of a combination of "Eww, PHP" from new management and "data scientists use Python." Character encoding was a huge, unexpected annoyance.
This is not what I expected -- my limited past experiences with anything outside of Latin-1 using PHP have been perplexing and not smooth (and I generally like PHP well enough). Can you elaborate on what features or approach can make things robust?
Tragically, Perl developed its "unreadable" reputation because it was the language du jour of the system admin/hacking world. The first time most people experienced Perl was by finding some crufty old script that glued a bunch of shell tools together haphazardly. Few developers today have actually seen what good, production Perl can look like.
No disrespect to the wonderful system admins of years past, but those guys were a different breed. They weren't programmers. But Perl still let them get their job done. Their unmaintainable messes caused a great deal of harm to Perl.
CPAN is great, but its hard sometimes when I just want to install something easy. It was the first great shared library and it shows its age a bit. Last time I ran it, it was compiling C code for some strange reason. We have trouble setting up shared perl environments, something we don'e have with python.
Biology has a lot of Perl code still, but it seems to moving to python.
Terrible code exists in many languages.
I think the "path of least resistance" is important: developers are time-constrained, understanding-constrained, lazy (if they're virtuous), etc. There's a big incentive to do whatever is easiest/quickest.
When I last used PHP, about 5 years ago, there were OOP APIs cropping up to replace many of the standard global functions; namespaces had just been introduced; closures had become useful; frameworks like Symfony (and Drupal 8) were becoming established, rather than the old "plugin" approach of throwing around arbitrary code and hoping for the best; dependencies were being managed by composer; files could be autoloaded from sensible locations; testing frameworks like PHPUnit and PHPSpec had become best practice; etc.
Yet all of those things were opt-in and verbose. The path of least resistance was still:
<html>
<body>
Hello <?php echo $_GET['name']; ?>
</body>
</html>
(For non-PHP programmers, this is appending a GET parameter straight into the page, which is an XSS vulnerability). Doing things "properly" took a great deal of effort and discipline.Compare this to something like Java: it favours class-based OOP so much that even "hello world" needs a class. The path of least resistance is to do things "right" (from Java's perspective). Haskell's path of least resistance is simultaneously easier ("hello world" is just `main = putStrLn "hello world"`) and harder (`main` uses the `IO` type, whose API enforces certain conventions).
Deprecation warnings, linters, etc. can help with this; but PHP's only real strength is its installed base of code and developers; changing the language too much would throw away this advantage (akin to being a new language, see Python 3 and Perl 6); not changing it enough prevents the more serious and/or systemic issues from being dealt with.
I wish the language designers and users luck, but I'm really hoping to never use it again ;)
You are absolutely right that the path to this has been fixing the path of least resistance. Laravel and other frameworks have made it easy to get variables using their preferred methods (and automatically sanitizing input). Learning resources (tutorials, docs) utilize the OO functions and many of the older functions were deprecated and have been removed for years. If you look at one of the more infamous functions, mysql_real_escape_string (https://www.php.net/manual/en/function.mysql-real-escape-str...) that was removed entirely in PHP 7. If you look at the more modern mysqli, they've chosen to have both escape_string and real_escape string, but one is an alias to the other. Similarly, sane defaults have become the norm, especially since most developers are using containers or VMs/vagrant to program. The one major outstanding issue is the api naming is still inconsistent.
On a sidenote, the PHP docs are great with pages showing examples and notes talking about potential issues. When I switched to python I couldn't believe how bad the docs were in comparison.
I've got nothing against DSLs and template languages and such, but most of the ones I encounter make me sigh and say, "I know you thought it would be easier but it's just one more thing I have to figure out how to debug, without any of my usual debugging tools."
I did get a little perverse amusement at writing HTML files containing nothing other than single `<?php` element; where that PHP's job was to generate HTML; and it did so via a templating language (e.g. Twig or Smarty)...
One thing that shocked me during my brief foray into PHP was how heavily popular PHP apps like WordPress rely on the filesystem. Want to move a site? Copy the database, and copy a bunch of files. It seems like there's a cultural expectation that applications run on a single server in your closet. Of course you don't have to write code this way... but people still do.
<?php echo "hello world";
There - no XSS, no HTML, no class requirements.
- The path of least resistance in PHP is often directly at odds with the "proper" way of doing things (including many things listed in this article).
- This is important because PHP's intended domain is Web development, so this can easily cause security flaws.
- Any attempt to "fix" this example will inevitably make it longer, more complicated, harder to remember, etc.
Your PHP "hello world" does not demonstrate those problems, since it has no XSS or HTML, so it is a poor example.
After this demonstration, I abstracted to the more general concepts of "path of least resistance" and "'proper' ways to do things", irrespective of language or domain.
To clarify my meaning for these phrases, and to demonstrate how language designers can use the former to push the latter, I gave two examples: Java pushing its preferred approach of class-based OOP, by disallowing raw, top-level statements; and Haskell pushing its preferred approach of monadic I/O, by enforcing the type of `main` and restricting the available APIs. Notice that neither of those examples make the "proper" way easier (that can be very difficult, in general); instead they eliminate anything that's easier (like top-level statements), such that the "proper" way is the easiest thing that's left. In other words, Java's requirement that even "hello world" be wrapped in a class is a good thing for Java programmers, since allowing top-level statements like `System.out.println("hello world");` would undermine the principles of the language. This general argument is not specific to PHP, and certainly not a direct comparison to the XSS snippet.
After defining and demonstrating these general concepts, I then returned to the specific case of PHP, to point out how backwards-compatibility with its legacy of easy, insecure approaches undermines the attempts to improve the situation. In other words, the "proper" way to write PHP (at least, back when I used it) is to use OOP, namespaces, type hints, escaping of user input, etc. Yet the design of the PHP language discourages all of those, by providing easier alternatives which are "improper" (like in my XSS example); and removing those alternatives (in the same way that Java forbids top-level statements) would break almost all existing PHP projects and require the majority of PHP developers to change their habits; and doing so would eliminate PHP's main selling point (installed base and developer mindshare).
I hope that clarifies why the comparison is not disingenuous (i.e. because I'm not making the comparison that you claim).
If I were to make a comparison of that vulnerable PHP code against something else, it would need to be against a language which is primarily designed for Web development (to avoid being disingenuous), and it should be designed to make the "proper" approach the easiest. The Ur/Web language fits these criteria nicely, and (from a quick skim of the tutorial at http://www.expdev.net/urtutorial/step1.html ) the equivalent to that PHP would be:
fun greet data = return <xml>
<body>
Hello {[data.name]}
</body>
</xml>
Not only will this will perform the correct escaping, it will also be a type error if another page tries linking to this one without giving a `name` parameter.PHP, on the other hand, requires manual escaping with htmlentities() ... It is very, very error prone.
That's not helpful. Laravel can objectively be the best web app framework in the world and I still won't touch it, because of PHP.
Predictability, minimum WTFs per minute, consistency, sane defaults -- these win over short-term convenience, every time.
Since then we’ve moved to a world where every program is web-based. I mean, even huge enterprise systems in healthcare run on some JavaScript MVVM framework and a web-backend in the cloud.
The truth is that php is more adapt at handling this than a lot of the stacks you see in enterprise. It’s really kind of silly, but I don’t think we’ll ever adopt php either exactly for its bad rep. But sometimes I wonder if we shouldn’t.
Laravel does this very well, not just by being a great framework but also in its ecosystem (Envoyer, Forge, Spark, Nova, Horizon, Socialite) and its documentation (https://laravel.com/docs/master).
I understand that PHP developers love it. It's orders of magnitude better than doing everything by hand. But no, thanks.
Compared to Django and Rails, Laravel has those two problems I said. I don't think I ever saw a benefit of Laravel compared to them, except for the easy to deployment of PHP (that is a mixed bag anyway).
The ASP.Net and Java frameworks are so different that any comparison could join Django, Rails, and Laravel as a single point. Everything on those languages is more bureaucratic and stable, easier to compose more complex projects, but harder to create simpler ones.
Compared to snap (I've used very little of Yesod, but looks like it's alike here), the trio Laravel, Django, and Rails compose pages much better (it's a shame really since "compose" and FP go hand to hand, and I expect that to change in the future), but the FP frameworks are much better for creating data services.
Laravel is fine for prototyping but it breaks backwards compat constantly, probably due to the massive amounts of over abstraction, not to mention layer upon layer of IOC hell.
Still over-engineered I guess but sometimes it means you won't have to go against the framework for some complicated tasks.
Prior to Laravel, the PHP way was minimal indirection and simple execution flow. I think it was hard to do something something different with Laravel, and definitely hard to do it in a way that offers performance and security and any other good thing you might want in addition to pretty code.
One disadvantage IOC/DI carry in every language and particularly in PHP is difficulty with debugging. If you have a file of functions and a template that generates HTML you could just read through the code yourself or use prints, now it can be hard to know where to put the print when each page load may involve a couple dozen files.
That, I believe, is IOC hell. My belief is you get through it by learning the framework internals, which is a lot of work (especially if you also have to fit something like Wordpress, Angular, your family, or Photoshop in your mind as well).
The problem is that it gets taken to extremes when it's done at the framework level.
The pattern tends to encourage overly decoupled abstractions that are nigh impossible to wrap your head around.
Dependency injection is useful when you need to decouple for testing. Other than that it's rarely useful.
If your trying to decouple everything because "coupling is bad mmkay" your just cargo culting.
IOC is just anti OO. And I'm anti OO. But when you use IOC for every class yove got a huge fucking problem.
The only time I've seen IOC work well is across module boundaries in a system where modules were boundaries that could not be crossed without the IOC.
Within modules usual namespacing and new constructors were used liberally.
This is one of my personal side projects, written in PHP and Laravel: https://github.com/brendt/aggregate.stitcher.io
Here's a list of all OSS package we maintain at work: https://github.com/spatie
This. If there isn't a linter that bombs out on those things that used to be standard PHP, modern PHP is a non-starter. There are too many bad examples out there that will make their way into modern code if you let them.
https://github.com/phpstan/phpstan
Lots of great static analyzers to run in CI and during development to catch all kinds of issues.
Also, https://github.com/FriendsOfPhp/PHP-CS-Fixer to clean up code syntax (configurable rules, has good presets).
PHP is not that language. Far to many sleepless late nights trying to clean up some security hole. PHP is like that abusive Ex that everyone says has changed. It may be true, in which case, good for PHP
But I won't be putting myself in that position again.
Maybe V language (vlang.io) could pique your curiosity.
PHP, javascript are not them.
Probably that's the reason why Clojure tends to be in top of the "developer happiness" polls.
It may in fact be that PHP has improved to the point that the relationship isn't abusive anymore. But I'll never go back to find out. PHP and me were done years ago.
Slightly off-topic, but I think that nowdays it's actually less of an argument than when PHP started becoming popular. The thing is, back in the days, statically typed languages were just bad and unproductive. Today, they are way better, and the fact that I can run my service on $3/month server with 900M of RAM and not think about the price tag at all is actually quite a decent argument to stay away from dynamic languages (but not the main one, tbh).
That's worth a lot to most people, I think?
> Is performance that much of a big deal for most people? Yes obviously. Performance is important no matter the language.
> the counter-intuitive behaviour of '==' You should learn the languages type system instead of assuming it works how you think. Again this is true of every language.
> I assume that these obsolete functions and operators still linger for backward compatibility? If so how do you avoid them? The built in linter gives you a warning that its obsolete.
The inconsistent naming and arguments. Dumb defaults and thousands of functions in a global namespace is the real problem and there is no solution to it. Oh and calling functions is unacceptably slow, that they can and need to fix the rest of this is just I like my language better.
> You should learn the languages type system instead of assuming it works how you think. Again this is true of every language.
A good language should have good ergonomics. Criticism that `123 == "123foo"` is not reasonable cannot be brushed away by claiming that users should RTFM (although arguably in this case it's less an issue with == than "123foo" being implicitly cast into an integer).
Maybe this has been fixed and is no longer relevant though (I'm citing the Fractal of Bad Design page).
See, as a commercial enterprise (begware as a business) all kinds of "foundations" and sponsorship pools surrounding the language already accumulated a big enough pool of clients who were happy enough with PHP as it was in 4.0 era. They had no intensive to progress. Especially if their business depended on "fixing brokenness"
Open source and sponsorship does not always mix well. Just as with front-end frameworks/libraries that live off sponsorships, eventually it leads to people prioritising pleasing sponsors, and working on pushing their software over improving the software itself.
The current allergy in JS world about genuinely required breaking changes is all about that as well. Any times a talk of genuine "JS 2.0" starts to entertain minds of powerful players in the JS world, there will be tons of people with commercial interest coming and extinguishing the conversation with "no, we absolutely can not ever break anything, ever, even if it is already broken"
Breaking changes in JS world do occur, but most of them being near accidental, security related, or being done as part of actual sabotage like intentional breaking of synchronous AJAX requests after they were shipped.
My logic is, if breaking changes are still unavoidable in JS, why not to do them in a controlled manner, rather than through sneaky sabotage ops like one above?
Wow that could not be more wrong. PHP definitely changes things to make the language better, especially breaking changes. PHP5 changed objects from value types to reference types -- you don't get a bigger change than that.
But they don't just change things willy-nilly -- they do try to maintain backwards compatibility as much as is reasonable otherwise it wouldn't still be PHP.
For most people outside VC-funded startups, yes it is. It is also an environmental concern, imagine if 80% of the web was running on ruby.
Most people don't understand that 99% of performance issues are not caused by language performance but by bad architecture and bad developers.
Always choose the best tool for the job, you rarely get to that scale and quality of software design that only the raw language performance is left to be optimized :)
If you build a Rails or Laravel app in the same way you would build a Java app, the Rails/Laravel app will be dead slow. And I've seen that happen. But if you know what you're doing you with Rails/Laravel it will be a long time before you say: we should rewrite this in Go/Rust/Erlang.
The main criteria for me when choosing a tool for the job is: how well does the team know the tool? can they use it at full potential?
I've been involved in java project with 20k monthly cloud costs. Most of the workload is handled in the background by consumers that pull messages from RabbitMQ. I'm pretty sure I could rebuild that with any language while actually reducing the costs because the bottleneck is not the code but the architecture. Would it matter if I would rewrite it in Java instead pf Python or Ruby, in terms of performance, yes, if we need to consider other things, like speed of development, etc it gets complicated again. :)
Maybe the wordpress guys have done a great job in rewriting the internals and cleaning things up in the last years, I wouldn't know, I don't follow their progress.
Performance is a concern for many people, and this is somewhat overlooked because of the number of people here who work for companies where scaling is the primary concern. I think this is what he meant by people outside of VC-backed startups. I know of multiple companies that have had outrageous cloud-hosting bills and have had to hire fancy consultants to fix it.
I see no reason to start any greenfield project in 2019 in PHP unless you literally only know or ever want to learn PHP. I could be wrong in terms of the entire language and it's ecosystem could have changed in the 18-20 years since I deliberated interacted with it last... We have a lot of things since mod php, so there's many other options, most of which don't involve PHP, so I suppose true fans will build their web apps in forth, I dunno...
Is performance that much of a big deal for most people? In a world where Ruby on Rail exists I find that hard to believe. Server are cheaper and vastly more powerful now than in PHP's infancy, I'm sure that for the vast majority of use cases PHP's performance (whatever it is) is good enough.
The infamous "Fractal of Bad Design" wasn't about that, it was about the ridiculously inconsistent and error-prone API, the insane defaults, the counter-intuitive behaviour of '==', the headless chicken development roadmap where maintainers would add features because they were popular in other programing languages without trying to figure out if they had their place in PHP,...
Surely a lot of this has turned into technical debt? Even assuming that "modern" PHP managed to come up with better ways to deal with all of this, I assume that these obsolete functions and operators still linger for backward compatibility? If so how do you avoid them?
Again, I personally don't really care, but if you want to win new converts who haven't been as scarred by PHP as I have been I think that's where you should focus your efforts. Maybe somebody should write a point-by-point rebuttal to the "fractal of bad design" article?