3 ms·
I 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 ar
by klibertp 14y ago
I 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.