Ask HN: Do you dislike PHP?
A lot of the readers seem to dislike or even loathe PHP. Why is it so?
7 comments
What I like: PHP has a good (and often overlooked/underrated) runtime, with language- and runtime-level support for running each HTTP request in a fairly isolated environment. It has a fairly standardized deployment model and a decent set of standard libraries, especially for common web development tasks. The built-in support for mixing code and markup in a single file makes it ultra-easy to hack together a simple web page or very small application.
What I don't like: The standard library has grown organically and without much top-down design, leaving it with too many inconsistent names/APIs, gaps and overlaps in functionality. Object-oriented programming took hold relatively late in PHP's history, so it's not used consistently in the standard library and elsewhere. The language itself has too many non-obvious pitfalls, e.g. ways that array/map indices work, and the way that type errors and type coercion are handled. Support for programming-in-the-large (e.g. first-class modules or packages) is poor. Historical convention of mixing logic and markup means it now requires extra discipline to separate them. The language doesn't seem to be evolving toward any particular vision, and it's not really flexible enough that users can evolve the language themselves (ala Ruby or Lisp).
I've worked pretty happily with PHP applications, and seen a lot of good code written in PHP. But it's not my tool of choice for new projects, for the reasons above.
What I don't like: The standard library has grown organically and without much top-down design, leaving it with too many inconsistent names/APIs, gaps and overlaps in functionality. Object-oriented programming took hold relatively late in PHP's history, so it's not used consistently in the standard library and elsewhere. The language itself has too many non-obvious pitfalls, e.g. ways that array/map indices work, and the way that type errors and type coercion are handled. Support for programming-in-the-large (e.g. first-class modules or packages) is poor. Historical convention of mixing logic and markup means it now requires extra discipline to separate them. The language doesn't seem to be evolving toward any particular vision, and it's not really flexible enough that users can evolve the language themselves (ala Ruby or Lisp).
I've worked pretty happily with PHP applications, and seen a lot of good code written in PHP. But it's not my tool of choice for new projects, for the reasons above.
I forgot another one: There's very little tool or library support for using PHP for non-web-facing scripts. I like being able to use the same languages and libraries for both web and non-web code, and to have my web apps use the large body of e.g. Ruby or Python libraries that weren't necessarily designed with web apps in mind.
PHP's sigils are superfluous. Perl (from which PHP derives their use) utilizes sigils with respect to typing in order to denote scalar variables ($), arrays (@) and hashes (%). What does PHP use the $ sigil for? Everything but references (&). Why? Because.
PHP's standard library is extremely disorganized. What's the function to put a string into hexadecimal? bin2hex. What's the function to put a string into base64? base64_encode. How do you turn a base64 string back into a "binary" string? base64_decode. How do you turn a hexadecimal string back into a "binary" string? Oh wait... an explicit function doesn't exist for that. Not to mention the various inconsistent ways in which functions are named: afnctn(), afunction(), a_function(), et cetera ad nauseum. Many functions also have an inconsistent order of parameters.
PHP doesn't support integral values larger than that of a signed 32 bit integer. Even better, when you overflow an int, you get a float back! Did you know pack() and unpack() support arguments for the unsigned ints that PHP doesn't support? Genius!
Last I checked, PHP didn't use lexical scoping. Do you know how downright stupid and annoying that is?
PHP's thread support sucks. Period.
According to Cal Henderson at Flickr, PHP "leaks memory like a sieve." (http://www.afup.org/IMG/pdf/flickr_php.pdf) (of course this is an implementation issue)
The downright stupidity of some of the PHP users just baffles me at times. One look on the PHP manual (Especially at any of the pages about the cryptographic functions, such as md5() and sha1() ) is enough to make any seasoned programmer's blood pressure skyrocket.
Cheers.
PHP's standard library is extremely disorganized. What's the function to put a string into hexadecimal? bin2hex. What's the function to put a string into base64? base64_encode. How do you turn a base64 string back into a "binary" string? base64_decode. How do you turn a hexadecimal string back into a "binary" string? Oh wait... an explicit function doesn't exist for that. Not to mention the various inconsistent ways in which functions are named: afnctn(), afunction(), a_function(), et cetera ad nauseum. Many functions also have an inconsistent order of parameters.
PHP doesn't support integral values larger than that of a signed 32 bit integer. Even better, when you overflow an int, you get a float back! Did you know pack() and unpack() support arguments for the unsigned ints that PHP doesn't support? Genius!
Last I checked, PHP didn't use lexical scoping. Do you know how downright stupid and annoying that is?
PHP's thread support sucks. Period.
According to Cal Henderson at Flickr, PHP "leaks memory like a sieve." (http://www.afup.org/IMG/pdf/flickr_php.pdf) (of course this is an implementation issue)
The downright stupidity of some of the PHP users just baffles me at times. One look on the PHP manual (Especially at any of the pages about the cryptographic functions, such as md5() and sha1() ) is enough to make any seasoned programmer's blood pressure skyrocket.
Cheers.
I like PHP. I also like what the did for the Open Source movement. It is free, with PHP>5.0 provided OOP support and has led the way all along. Without PHP there would have been no Drupal, Wordpress, Joomla, my early websites etc..
The dislike comes mostly from purists and language evangelists who think the language is what makes a good programme.
I started programming ages ago. From Fortran, Cobol, Algol moved to Pascal (the greatest ever), went to C and the rest of them.
PHP has a lot of heritage that I object like sometimes function names are either full name or c-like. I bypassed them by wrapping a couple of functions and presto!
The dislike comes mostly from purists and language evangelists who think the language is what makes a good programme.
I started programming ages ago. From Fortran, Cobol, Algol moved to Pascal (the greatest ever), went to C and the rest of them.
PHP has a lot of heritage that I object like sometimes function names are either full name or c-like. I bypassed them by wrapping a couple of functions and presto!
I think a lot of the "Man I hate PHP" sentiment is really directed at the corpus of programs written in PHP rather than the language itself. I think it's popularity and accessibility to novice programmers has left PHP with a legacy of badly thought out and unmaintainable code in production that may even be worse than Perl 4 (and Matts Script Archive) ever had to deal with.
I love it and I hate it.
I love it because it allows me to very quickly build stuff but I hate the inconsistencies that make it almost a requirement to visit php.net all the time.
And then there's a bunch of very ugly bits and pieces that now have to be supported forever due to backwards compatibilty. Strpos anyone ?
I love it because it allows me to very quickly build stuff but I hate the inconsistencies that make it almost a requirement to visit php.net all the time.
And then there's a bunch of very ugly bits and pieces that now have to be supported forever due to backwards compatibilty. Strpos anyone ?
Like all languages, it has it's place. I dislike it when it's used out of it's place, but I quite enjoy it when it's used properly.
I agree. A lot of complaints I've seen about the language, beyond its inconsistent function names and the occasional argument, are from people expecting the language to be more than it is. Different languages exist to address different problems and serve different purposes/platforms. Perhaps PHP is lagging behind Python and Ruby, but it's by no means a useless language.
I like PHP. I'm a .Net developer, but I started out with PHP and it's great to go back and use it from time to time. PHP has come a long way in the last 5 years and from what I've seen, the quality of frameworks and applications written with it have evolved a lot as well.