DHH on the immediacy of PHP (2008)
david.heinemeierhansson.com
david.heinemeierhansson.com
PHP enables really rapid development: just save the file and reload in your browser to see a change, compared to Java/CGI-C which need recompiles.
And finally, PHP is written expressly for the web, not like Java, Python, Ruby or whatever the latest fad is these days - where web stuff was bolted on instead of baked in the design and operations of the language.
This is the reason why PHP is still my go-to first choice when it comes to request-based server apps (and together with Node.js it's also a good option for continuously-running applications). For me, the sore points of PHP are its syntax, scoping behavior, and the awkwardly structured standard library - to the point where I occasionally look elsewhere, or consider building an alternative myself.
It makes reasoning about state easy because you don't have to consider it. In my experience (which involves several large and mature PHP codebases), that's not a good thing.
You're right about the benefits, but the downsides are glaring too.
I blame both of these on the messaging and marketing coming out of Zend and the surrounding ecosystem, namely that PHP is supposed to be a language where big applications are constructed with convoluted EE-like class trees, and that PHP is supposed to be a beginner's language. Both of these constitute an outright failure to recognize where its strengths and weaknesses lie, in my opinion, by the same people who are maintaining the language.
The difference between PHP and application servers is that all its runtime environment is reloaded from scratch at every request. This is both a good and a bad thing.
I don't think this matters at all.
Python and Rubi in particular have much better constructs for web development than PHP could ever get (because of its lack of state mainly).
"Bolting" things on top of a general purpose language is exactly what those languages are designed to enable.
In my view, PHP's main feature is that it enables an smooth transition from static pages to fully dynamic ones. That's responsible for a lot of its popularity, but is not a good feature to consider when starting a new project.
Is it though? How come something written expressly for the web does not include a simple and safe way to output untrusted input without being vulnerable to XSS attacks?
<?php echo htmlspecialchars($var) ?>
is a joke.Although, to be fair, the solution to this is still the same as with any other web-facing language - use a framework (which will, eventually, just wrap htmlspecialchars around everything for you.) It just happens that other languages make those decisions for you and PHP doesn't. Developers pretend those languages are more "secure" when really the ugly low level stuff is just already hidden behind abstractions before they even approach a project.
By tainting, the & in the & would be double escaped as $a would carry its taint over to the output string. No thanks, I like to know what is escaped and where.
Hello & Welcome {{a}}
but despite being "built for the web", php is not a sane templating language for dealing with html.Facebook's XHP solves this problem:
https://github.com/facebook/xhp-lib#escaping
"An interesting feature of XHP is the idea of automatic escaping" ... "As you can see, using XHP makes safety the default rather than the exception."
Unfortunately your standard php hosting site is not running hhvm.
What does "being written expressly for the web" mean in the context of PHP? Does it mean they implemented a taint mode like Perl, where you could sandbox untrusted user input. Well... no. Did they implement defenses against common web vulnerabilities like SQL injection? Not really. In fact, a lot of the built-in string escaping functions in PHP are seriously broken and will lead to security vulnerabilities if you use them. Is it part of a bigger web framework like Ruby on Rails? Nope. As far as I can tell "being written for the web" is just marketing.
Prepared statements has been available with PDO since 2005. It might very well have had bugs, but that isn't uncommon.
I'd argue PHP truly shines on the command line, when I need a script that does what I need and quick. OS X comes with PHP built in and this is wonderful. The invention of phar's akin to Java Jars has made these even more portable, such that you can include all dependencies in a single file.
Python is a nightmare especially when you copy and paste stuff together from the internet because spaces and tabs are a different thing, Perl is next to unreadable (but immensely powerful) and Ruby is exotic at best. Then there are bash scripts, a drama in itself and only to be used when you want cross-platform/cross-distribution compatibility.