4 ms·
The standard gripes about PHP: - PHP's syntax is very random. There are over 5000 builtins and no consistency among them. - PHP lacks (or lacked until relativ
by neilk 16y ago
The standard gripes about PHP:
- PHP's syntax is very random. There are over 5000 builtins and no consistency among them.
- PHP lacks (or lacked until relatively recently) many programming niceties such as objects, types, closures, lambdas, and namespaces. To do anything interesting, PHP developers rely on globals or dubious innovations such as using a string as a function name.
- PHP relies on a web-serving model where the program invocation is done in milliseconds. Even if you can (with difficulty) use PHP libraries in command line programs, it's very inefficient for anything like a long-running daemon process.
- Although it is almost always built into a web server, PHP doesn't make it easy for you to do anything useful with web requests -- such as custom authentication in a separate phase from content generation.
- Since it's a web templating language at heart, PHP practically begs you to do the wrong thing and mix presentation and data. To solve this, many shops use a templating language on top of PHP, which does feel kind of silly.
- Due to its ubiquity, PHP is the choice of script kiddies who can't program. The comments on the PHP.net documentation site are mind-numbingly naive sometimes. So even experienced programmers feel dirty using PHP.
That said:
- Among comparable languages, and for typical web serving tasks, PHP is fast. Really fast.
- It's probably already installed on your platform of choice.
- Within the web-serving paradigm, it has almost everything you would ever want.
- Its model of programming is really brain-dead, but it also can keep you out of trouble since you're forced to do everything in a REST-compatible manner.
- It's also the choice of websites like Yahoo, Flickr, Facebook, and Wikipedia, so you know it is battle-tested.
- runT1ME 16y ago>PHP is fast. Really fast Compared to WHAT? Ruby and Perl? Cause I hope you're not saying it's C fast, or even java or C# fast...
- neilk 16y agoAmended.
- bl4k 16y ago"until relatively recently" if by recently you mean 6 years. almost everything else you said is also wrong. op - use what you are most comfortable with and don't force yourself into whatever is cool or latest groupthink (Edit: ok you got me.: * PHP's syntax is very random you are confusing syntax with the standard lib, which was inherited from C func for func (which if you come from an OO stdlib can seem 'random' - but it makes elegant sense in the old unix world where CamelCase object names didn't exist) * PHP lacks (or lacked until relatively recently) many programming niceties such as objects, types, closures, lambdas, and namespaces see php5 - 2004. * Even if you can (with difficulty) use PHP libraries in command line programs tons of daemon scripts run php - you are talking about a php3/4 problem (set_script_timeout etc.) see mailchimp post * Although it is almost always built into a web server, PHP doesn't make it easy for you to do anything useful with web requests this is what PHP excels at. want a function to retrieve the hostname from a URL? done. want to send a HTTP header? done. want to parse basic auth? done. php.net/parse_url $_SERVER php.net/header PHP was probably the first http/web aware language, you picked its strength as a weakness. * Since it's a web templating language at heart, PHP practically begs you to do the wrong thing and mix presentation and data. you can say that of any language, implementation-dependent. python and ruby also print to stdout which is just the web process as well. you think this because you have seen more php scripts that mix presentation and logic. * Due to its ubiquity, PHP is the choice of script kiddies who can't program. sigh
- ahi 16y agoAs far as I'm concerned, php5 was still broken until 5.3. http://php.net/manual/en/language.oop5.late-static-bindings.php http://php.net/manual/en/language.oop5.late-static-bindings....
- wanderr 16y agoWe just got bit on the ass by this one yesterday. (still deployed on 5.2)
- neilk 16y ago"relatively recently" PHP 5.3 came out in June 2009. Quoting from the readme: The key features of PHP 5.3.0 include: * Support for namespaces * Late Static Bindings * Lambda Functions and Closures I don't know what you are even arguing about. PHP has a sort of support for types, but while you can say that a function accepts a certain kind of object, you can't express that a particular function takes an int or a string. That's really pathetic. It's fine if you don't want a language with types -- many great languages don't have them -- but only PHP thinks that stupid half measures are acceptable. PHP has had objects for some time, but it arguably didn't work well enough until their second try. It's true that PHP makes it very easy to get at elements of the web request, but what I meant was that it is trapped in the content-generation phase. The Apache API is very sophisticated and gives you full control over the HTTP response cycle, but PHP throws all that way, and turns Apache into a dumb teletype. So every PHP script that needs to do authorization is written in this silly inside out way; first you start to deliver content, and then you check if you're allowed to actually do so. Whereas the right thing is to check authentication and authorization first, and then never even call your content script if the user's credentials didn't check out. Apache nicely separates this out with their Authentication, Authorization, and Content phases, but nobody told PHP. Other web frameworks don't have this problem either (I've used some web servlet engines written in Java, and they too avoid the brain-damage of doing it all in the content-generation phase.) As for daemon scripts, I have no direct knowledge, but there aren't a lot of people who would suggest it's a great language for a daemon. Even fork() can be problematic in PHP. I wrote a system that tried to use it that way and we ran into all sorts of reliability problems (none of which I've ever encountered writing similar programs in Perl). I may be more behind the times than others, since I happen to have worked on three different PHP projects that all started around 2003-4 or earlier (and are still chugging along). After being bitten in the ass by various broken features over the years, most of them have adopted a very limited subset of PHP (some even refuse to use objects, to this day), and I can see why. I mean, PHP can be confused by something as simple as loading libraries from different script files. Rasmus' official advice to us was to have one "loader" script that included all the libraries in one shot. I find it hard to respect a language that has difficulties with things like this.
- dools 16y agoThis is a good summary of the common gripes. I would like to add to this list the history of things BREAKING even with minor version updates (although to be fair a lot of this has been due to radical changes in the object model over the past few years). I also think there's a fundamental problem with this question. I think one must make the comparison between web development frameworks, rather than saying PHP/Ruby/Python - you need to say Symfony (or PHP framework X - I just happen to like Symfony), Rails or Django (or Spring or Grails or whatever). In that case: the comparison is simple and personal. Go to the Symfony tutorial, go do the Django tutorial, go do the Rails tutorial. See which one clicks the best. I personally find PHP enjoyable to use because I've used it for a while and I'm used to it's idiosynchracies. I've used it for web development but I've also used it for command line daemon processes that have run, without fail, for the past 3 years. I've never had cause to benchmark those processes in terms of performance with any other language because I've never run into performance problems, but your mileage may vary. In short: I think PHP gets a lot of bad press - but PHP also gets a lot of things done.
- byoung2 16y agoPHP's syntax is very random. There are over 5000 builtins and no consistency among them. This is one thing that really annoys me about PHP...for example there is stripslashes() to remove slashes but strip_tags() to remove html tags. Why couldn't they be consistent about using the underscore or not using it. Another one is array_push($array,$var) which takes the array as the first argument and the $var to push as the second, whereas array_search($var,$array) has it in reverse.
- wanderr 16y agoThese complaints are valid, it is annoying but fortunately the docs are extremely easy to use.