PHP Just Grows And Grows
news.netcraft.com
news.netcraft.com
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.
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.
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.
That being said, the PHP ini is a config file that defines some of PHP's runtime parameters and, in some cases, controls modules and drivers that have been installed for PHP. The closest thing I can think of comparing it to would be the JVM config.
I use PHP for a crapton of scripting as well, namely scraping, which has nothing to do with PHP's web app capabilities as that all leverages curl.
While obviously a bad practice, it also enables non-devs to organically learn the language in bits and pieces. Sometimes they move on to create hugely influential platforms like MediaWiki and Wordpress, sometimes they just build very hard to maintain websites. PHP in a nutshell.
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...
@$arr['key']
is the same as $er = error_reporting(0);
$arr['$key'];
error_reporting($er);
unset($er);
Probably more importantly is that the internal errors are still being raised, there's just additional comparison logic within the PHP engine to suppress them internally.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.
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
Heck, the second Google hit for "php mvc framework" for me was a 2009 guide to writing your own (talk about not getting the point of a framework). There were two more pages in the top ten for PHP MVC framework comparisons.
Ha ha ha... yeah... writing your own php framework... who would do such a thing...
I understand why it's supposed to be a bad thing but I also think it helps to understand the principles involved in frameworks and the mvc pattern, and one way to do that is try to make your own. Then when you pick a real framework it won't seem like magic.
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.
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.
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.The GP is using a very well thought out configuration; this is using the right tool for the job incarnate. If I wasn't lacking in SQL department I would probably do exactly the same (probably replacing PHP with something strongly and maybe statically typed).
[1] SQL and XML seems a bit redundant, but I don't know what they are used for exactly. Also I lumped both SQL and XML together as "relational" because of XQuery, but I admit that I don't know much about the latter and this may be not accurate.
Using XML allows means the data associated with every "page" in the system automatically doubles as a service (SaaS). XSLT allows those those services to be translated into JSON, ASCII, PDF (via LaTeX), XML, or the format du jour. With this architecture, the amount of time to publish a new export format for every "page" in the system is reduced to the time it takes to write a new XSL template: hours to a few days.
All pages can reuse the same code to render themselves:
$data = get_xml( $id );
$xml = get_xml_dom( $data );
$xsl = get_xsl_dom( $stylesheet );
$proc = get_xslt_processor( $id, xsl );
echo $proc->transformToXML( $xml );
This cleanly separates business logic and the data model from presentation, plus much more. Perhaps it is masochism, though. ;-)Having to duct-tape XSLT on top of PHP just because PHP can't cut it is rather perverse.
The only thing I can think of that's worse than "programming" in XSLT is ColdFusion.
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.
.Net languages aren't immune to this either, particularly Windows.Forms and ASP.net. To write decent code in those, you basically have to fight the IDE and the framework every step of the way. ASP.net MVC makes it much easier to write good code, at the cost of being harder to user if you don't already know what to do. Your average newbie can't just point and click until he's half way there.
PHP has decent frameworks, like Symfony. They make it much easier to do the right thing, and harder to do the wrong thing, at the cost of being more difficult to learn.
Props to the Symfony team though. They're still trying to make something good out of PHP long after most other decent developers abandoned the platform on favour of something less newbie-driven. It helps a lot to have that kind of framework available, just in case I have to use PHP for something.
Edit: Accidentally said that ASP.Net MVC encouraged bad code, but meant it encouraged good code.
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.
Moral of the story is, it's just whats in season this year. Some people will argue better languages, but really there are problems with all of them.
"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.