4 ms·
PHP has no shortage of weirdnesses and warts, but it occurred to me recently that no other major language was created expressly for the purpose of rendering web
by lukifer 14y ago
PHP has no shortage of weirdnesses and warts, but it occurred to me recently that no other major language was created expressly for the purpose of rendering web pages. All the other major contenders (Python, Ruby, Java, etc) are, for better or worse, general-purpose programming languages, which are pressed into service for rendering HTML strings using various libraries and frameworks.
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.
- klibertp 14y agoI haven't programmed in PHP for a long time and I could have forgotten, but I don't think there are many (if at all?) web specific language constructs. There are many things in standard library tuned for use in a web environment, that's true, but they are not a part of the language. The only thing I can think of as a web specific in a language itself is a '@' thing used for silencing errors. 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.
- jtreminio 14y agoYou'd turn error reporting off completely for prod anyway. Please don't use @
- klibertp 14y agoI won't, because I will never again use PHP :) 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.
- fein 14y agoI use PHP every day, and kind of take pride in that. We get a lot of shit for this labor of love, but damn do I enjoy it. 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.
- nir 14y agoThe part where PHP files are essentially HTML files (ie you can start with a file consisting of "<b>hello world</b>" and add some code as you go) is where the made-for-web really shows. 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.
- nnq 14y agowhat about all the simple cases where one could replace the more verbose: 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...
- Firehed 14y ago@ is extremely slow. @$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.
- bpatrianakos 14y agoIs there such a thing as web specific language constructs? The way I see it language constructs are language constructs no matter where or how they're used. I think the main point to keep in mind here is that PHP was made for the web while other popular languages used on the web were created moreso for the purpose of being general scripting languages.
- klibertp 14y agoYes of course, certainly there are language constructs or features specific for some domain. That doesn't necessarily mean that such constructs can't be used in other contexts or domains (sometimes they can, sometimes not) but they were introduced into a language with a specific domain in mind. 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.
- lukifer 14y agoI'm using the term "language" very loosely; you are technically correct. To be clear, I'm referring to the 5000+ global functions, as well as the myriad classes, that are part of PHP's standard library.
- daenz 14y ago> no other major language was created expressly for the purpose of rendering web pages. 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.
- 27182818284 14y agoSimilarly, I don't think the set up time has been addressed by any of the other choices in language out there. It is really easy to choose N number of hosts and drop an index.php file into the folder. There are global companies that still hire small firms that write PHP for one-off contests, etc.
- Firehed 14y agoI'd say it started closer to making C more accessible for web programming (no fussing with pointers, memory allocation, bounds checks, etc), which incidentally makes it really easy to present content. It's also the reason for the inane naming conventions in lots of the "core" stuff. 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).
- ptbello 14y ago> there's no one go-to framework for MVC work I would say there's a lot of consensus around Symfony http://symfony.com/ http://symfony.com/
- Firehed 14y agoNo more or less than Cake, Zend, CodeIgniter, ... 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.
- Legion 14y ago> PHP has no shortage of weirdnesses and warts, but it occurred to me recently that no other major language was created expressly for the purpose of rendering web pages. All the other major contenders (Python, Ruby, Java, etc) are, for better or worse, general-purpose programming languages, which are pressed into service for rendering HTML strings using various libraries and frameworks. 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.
- thangalin 14y agoI use the following architecture: 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.
- astrodust 14y agoXSLT plus PHP? Are you a masochist?
- klibertp 14y agoWhy do you think so? This makes perfect sense to me - imperative language wraps purely functional one, and sits on top of declarative, relational language(s)[1] for data storage and manipulation. 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.
- 14y ago
- rorrr 14y agoI do PHP a lot, and no serious project uses PHP dirctly to render HTML. Well, I've seen PHP templates, but they are always separate from the actual 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.