46 points · by taylorbuley · 13y ago · 63 comments
The common wisdom is that PHP's success is due to ubiquity, deployment, and low barrier to entry. While all those are true, the fact that so many web-focused tools are baked into the language itself (meaning minimal time to hunt/learn/evaluate third-party libraries) shouldn't be ignored.
For non-trivial web applications, the "rendering HTML strings" is one of the smallest parts of the job.
The lack of separation between application and HTML output in PHP may be an asset when starting out or when making lightly scripted web pages, but when creating an application that just happens to be served up over the Web (and possibly served up other ways too), those general-purpose languages are much more natural fits for the job.
If you echo HTML, you get HTML. If you echo binary data, you get binary data. JSON, XML (including SOAP bodies), text, nothing at all, file i/o, direct socket connections, exit codes - all are supported equally well. The only thing vaguely related is the HTTP headers that you get for free if you're running it behind a fastcgi module (apache's mod_php, nginx/php-fpm, etc).
You can write a single PHP file that includes HTML, Javascript, MySQL, CSS and PHP, but that would make you a bad developer, or it's such a simple one-off thing that you don't worry about it.
Or, you can develop with maintainability in mind and separate those 5 concerns out.
Tools facilitate workflows. The fact is, PHP very strongly facilitates your "bad developer" path. That's why there is so much PHP code that goes down that path, compared to other languages.
Yes, you can go off on a better path. But better designed tools make it much more easy and natural to do things the "right" way.
PHP makes your "bad developer" path the path of least resistance. That's bad.
Browser -> POST -> Database -> XML -> PHP + XSLT => HTML
Prevents HTML from being mixed with PHP. PHP becomes the "controller" in the MVC world. This makes the application easy to migrate to another language.On the other hand there are languages like Opa and Ur/Web or Racket instaweb dialect which do include language construct specific for web, for example static typing for forms, send/suspend or statically typed xml expressions.
I may be wrong on this and I would welcome a correction from someone better informed on the matter.
For example Erlang's `receive...after...end` and `!` are language constructs that are specific to the domain of message passing concurrency and they cannot be used for anything else. On the other hand Erlang's bit syntax is specific to the domain of writing binary network protocols but can be used for extracting data from binary files or constructing chunks of bytes for interoperability with C (structs).
There are many more such examples in various languages - despite being "general purpose" they frequently include features and constructs useful for some specific domain - it's a natural way the languages are created and evolve.
Please don't use @
Oh, I just thought that maybe php.ini is another thing that's specific to the web... But I'm not sure, for example there is site.py file in every Python distribution which effectively serves the same purpose, just uses Python instead of ini format.
Anything else in the language? I'm really curious.
if (empty($arr['key']))
with: if (@$arr['key'])
?People have started using this and I find no reason to tell them "it's bad practice", although it only spares 5 chars typing...
Unfortunately, as far as I can tell, it was created from the View perspective of MVC. PHP in my mind is equivalent to the special language of a template processor library of some other more general language.
I strongly disagree with your implication that it's only useful as a presentation layer, however. Some quirky syntax doesn't at all make it an incapable language; the real problem in my eyes is there's no one go-to framework for MVC work, a la Rails or Django (there's no shortage of choices, but that's not necessarily a good thing).
I would say there's a lot of consensus around Symfony
That's not what I meant. I meant that it was created from the perspective of a View. There's no other reason that php code has to be delimited with <?php ?>, other than it was originally designed to be embedded in html. This alone shows how the creators envisioned PHP to be used.
I think PHP's success is due to several factors:
1) Easy to set up and start. It even has a built in web server now.
2) Lots of useful functions.
3) Lots of useful extensions.
4) Weak datatypes. Newbies don't have to deal with too many error/warning messages. (and yes, i wish PHP had a strict typing mode).
5) The documentation is absolutely amazing (at least for the popular things).
6) The community. Even before StackOverflow, your PHP questions would be answered instantly.
Yes, PHP has its problems, and it does allow you to easily mix the PHP, HTML, JS all in on file, but while many people consider that as a path to shitty code, I consider it an easy way to tinker and try things, which is very valuable for beginners.
It's the reason I picked it up back in 2001. Being a C programmer up until that point it made the transition to web development incredibly easy.
On a side note, I still remember how awesome being able to do `"some string" == $var` was.
A novice can just pick up PHP and run with it. She can start blindly with unstructured code, then move to methods, then finally to OO.
The downside, of course: http://www.flickr.com/photos/raindrift/sets/7215762949290803...
[1] http://news.netcraft.com/wp-content/uploads/2013/01/php-tren...
For a starting developer, does it still make more sense to learn PHP?
You'll have to be extra-diligent about making sure the sources you're learning from aren't full of security holes, however.
If you want to see quality, look to the new generation PHP frameworks: Zend Framework 2, Symfony2, for example.
However, newer projects and startups are moving towards Python and Rails so if your goal is to be in that game, learn one of those.
There's an immeasurable amount of new work to be done in PHP. You have absolutely no numbers to back up your statement.
"our shared host is PHP only, we don't want to change for another" "we want wordpress" "our computer guys know a little PHP, we need PHP" "what the fuck is Ruby ?"
So you'll try to educate your client, to explain why Ruby us great. But you'll fail, because most clients don't give a shit and, for their very basic needs, PHP is as good as ruby.
(not that I know either... yet...)
If you want to get your feet wet with a multi-user web application, I recommend trying Sonata's sandbox: https://github.com/sonata-project/sandbox#installation
Composer just happens to use packagist as a default repository. It alone is not a repository.