share
Stack OverflowWhat makes PHP a good language?
[+536] [43] Jason L
[2008-11-21 16:16:42]
[ php programming-languages ]
[ http://stackoverflow.com/questions/309300] [DELETED]

I made a tongue-in-cheek comment in another question thread calling PHP a terrible language and it got down-voted like crazy. Apparently there are lots of people here who love PHP.

So I'm genuinely curious. What am I missing? What makes PHP a good language?

Here are my reasons for disliking it:

Worst of all, PHP convinces people that designing web applications is easy. And it does indeed make much of the effort involved much easier. But the fact is, designing a web application that is both secure and efficient is a very difficult task.

By convincing so many to take up programming, PHP has taught an entire subgroup of programmers bad habits and bad design. It's given them access to capabilities that they lack the understanding to use safely. This has led to PHP's reputation as being insecure.

(However, I will readily admit that PHP is no more or less secure than any other web programming language.)

What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.

So convince me otherwise!

(80) There's no satisfying answer to your question. I can substitute any other language/tool for PHP in your question. - Robert S.
"# Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer." Isn't that true of C / C++ too? - Ben
(5) It is horrible. - Andrew Medico
(4) I'd add another item to the list: encouraging direct interfacing with a specific database (via the mysql_* functions in the global namespace) instead of a portable interface layer, and encouraging unsafe SQL via mysql_escape_string and friends instead of bound parameters by default. - Andrew Medico
Well, I started a question stating that I don't like PHP (I may have said "loathe.") It got promptly voted down and you could almost see the wrinkled noses and raised eyebrows in some of the commentators :-) - Leonardo Herrera
(12) Oh, I remember another thing about PHP: T_PAAMAYIM_NEKUDOTAYIM What the...? - Leonardo Herrera
Some people just seem to love it, kinda like macs I guess, makes no sense to me, but whatever floats your boat. You can write [strike]cobol[/strike] php in any language though... - seanb
(4) Your ass got downmodded because you were trolling and adding nothing to the discussion. At least now your trolling IS the discussion. ;) - Nathan Strong
(2) @Leonardo: Foreign languages are scary, aren't they! Whatever shall we do? It means "double colon" in Hebrew, the native language of the original PHP designers, and it's easy as anything to google for. - nickf
(6) @nickf: There's no justification for its use, it's just a joke which makes no sense. Easy to google or not, no good reason for it. It's like every PHP fault, you can look to the other side and ignore it, or you can get annoyed as hell about it. - Vinko Vrsalovic
(62) it is horrible, but that doesn't matter. totally irrelevant. - Jeff Atwood
(2) I spend so much time dealing with PHP, and its worse than attending a meeting someone has called because they are lonely on the eve of a major deadline. I cannot stress how much I dislike PHP. - cfeduke
(3) "PHP ... will happily attempt to magically convert an array to an integer." "Isn't that true of C / C++ too?" ANSWER: No, C and C++ won't do that unless you ask (int i = int[] will not work in C or C++). - Max Lybbert
(18) Every symbol needs a name in the lexer/parser. T_PAAMAYIM_NEKUDOTAYIM refers to the :: symbol. It's a conceit by an Israeli developer from long ago - and it means "double-colon". :-) - staticsan
(3) I disagree with "totally irrelevant". It's not as relevant as most people think, but it can still have a negative impact. Great coders can probably build great stuff with Intercal, but not everyone is a great coder, and wouldn't it take less time, using some other technology? - Mindaugas Mozūras
(4) A bad workman always blames his tools! - Jay
(4) PHP : The best shotgun to shoot your foot. There's no better tool for this around. - Andrei Rinea
(1) It is horrible. I agree with Jeff Atwood but would rephrase it as "it may not matter". - Keltia
(1) haha - check out 'related questions' on the right. it came up with 'Should I use multiplication or division?' and 'When can I start teaching my son to program?' - Simon_Weaver
(1) It's pretty horrible. But it's well-known and works, most of the time. - community_owned
(108) To all people who use the "but it works" argument: One can write programs in brainfuck, one can write websites using c++, one can write GUI apps using assembler,... and guess what, it works! It's one of the most STUPID arguments, sorry. - ivan_ivanovich_ivanoff
(2) PHP really sucks. Bottom line. - Josh Stodola
(5) Do like I do: don't use it. Even better, don't learn it. If you know it and don't like it, just pretend that you don't know it anymore. Delete it from your cv. - Daniel Daranas
(1) @ivan: I would write a GUI app in assembly, and it would work, AND it would be awesome. Also, read: roller coaster tycoon - Carson Myers
(2) +1 : I would not start a PHP project today under any circumstances. I heard that in hell, they burn souls under a big stake made of perl and php manuals. In heaven instead, they get high smoking the python ones. - Stefano Borini
(7) +1 for mentioning implicit type conversion. Implicit type conversion is hideously evil about 99% of the time. And in that other 1% of the time, explicit type conversion is merely an inconvenience. - Daniel Pryden
Tired seeing these same no propose "question".. Don't like it. Don't use it... End of story. - Fábio Antunes
(61) "There are only two kinds of languages: the ones people complain about and the ones nobody uses" -Bjarne Stroustrup - DShook
(4) @ivan: No, it's not a stupid argument when "it working" actually refers to doing stuff with it, not the stuff that's done with it. You see, brainfuck or GUI apps using assember wouldn't actaully work. The application would, but the process of writing - ugh, not. - Ilari Kajaste
(2) @Daniel: PHP does have some actual problems, but implicit type conversion is really a design feature - that is, many people like it. You might not like it, but that doesn't make the language evil or bad in any objective sense. - Ilari Kajaste
(1) Everybody complains about php, what should we use then? :) - mnml
You forgot to mention the best worst-thing about PHP: the recent implementation of ...gasp... GOTO php.net/manual/en/control-structures.goto.php !! In 2009 for crying out loud! Un-freaking-believable... - hopla
(2) @mnml: Asp.net is a good alternative that lets you do things the smart way. :) - Karim
(2) Meh, PHP is like the pea soup you make at the tail-end of the camping trip; it just works, it uses all your available resources, it holds you over, it's mildly appealing in a way you don't understand... Take your pick, or write your own. Either way, it's still my chosen language. - Martindale
What about the problems of running multiple versions on an IIS server? I can run all flavors of .NET on one server no problem. Getting each PHP version to work in IIS has still befuddled me. - Josh
(2) ""There are only two kinds of languages: the ones people complain about and the ones nobody uses" -Bjarne Stroustrup" - but what he fails to mention is that they are often the same language :-) - Mawg
(2) What, you want us to trick you? - flexxy
The greatest thing about PHP is that it's simple enough, and the documentation with real-world examples is copious enough, that one can easily start coding in it without actually ever learning the language, and this is indeed what most users do. Then again, that's also the scariest thing. - ShreevatsaR
"There are only two kinds of languages: the ones people complain about and the ones nobody uses" -Bjarne Stroustrup. Comes as no surprise that Stroustrup has said this. I imagine Guido or Matz would have never said something along those lines. - Vinko Vrsalovic
(1) @Vinko: What? Ruby and Python get plenty of complaints: Ruby gets complaints from Python, Perl, and PHP users, and Python gets complaints from Ruby, Perl, and PHP users. :-P - Chris Jester-Young
If you were downvoted because of a comment criticising PHP, it doesn’t imply that people like PHP. It only means that people didn’t like your comment. I don’t like PHP, but I still think that certain prejudiced criticism against PHP may be unjustified. - Timwi
"There are only two kinds of languages: the ones people complain about and the ones nobody uses" -Bjarne Stroustrup - Stroustrup wrote this before C# - Chris S
While I mainly live on PHP, absolutely agree with #1, #2 and #8. These quirks should find no excuse. These are among the annoyances that PHP internals are trying to get rid of. - Halil Özgür
I can't convince you but I may introduce you to a recent displeasing speculative news story: Google: uses (mainly) Python, Facebook: mainly PHP. And yet great people are running from Google to Facebook. It's said that ~12,5% of FB workforce consists of ex-Googlers. It looks like language greatness is not among the most influential factors in real life, unfortunately. - Halil Özgür
Why should I wait PHP to get features that I can have with other languages and features that are better implemented? Just pick any web oriented langauge, and everything is implemented better than PHP. I don't except much from language that has so many bugs!! - newbie
[+624] [2008-11-21 17:55:32] Peter Bailey [ACCEPTED]

I'll take a stab at responding to each of your bullet points

PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

I both love and hate this topic. Because at its core, this issue is correct. Why are some bi-word function split with an underscore, and some aren't? Why do needle and haystack parameters swap positions in the argument signature sometimes? It's ridiculous. But at the end of the day... does this really matter? My IDE with intellisense and php.net just a browser click away, this is just plain not that big of a deal. Is it a negative against PHP as a language? Yes. Does it hinder my ability to be an effective programmer? No.

The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.

Personally, I think this is not a good point. Deprecation is necessary to the evolution of a language, especially one that has as much kruft as PHP does. PHP gets a lot of flak for "making it easy to be a bad programmer*" but at the same time, the PHP group also gets in trouble when they try to remove stupid constructs from the language, such as call-time pass-by-reference. Eliminating call-time pass-by-reference was one of the best moves they ever made. There was no easier way for a novice developer to shoot themselves in the foot than with this "feature".

A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!

I don't think there's a general lack of consideration at all, I think you just got stung by this particular change and have been left with a sour taste in your mouth. Language changes are often known months if not years ahead of time. A migration guide was provided for the move from 4 to 5, and the version differences are documented in the manual. Call-time pass-by-reference was a horrible "feature" and doesn't give the developer any expressive power they can't get by other means. I'm glad it is gone (along with other crap like magic quotes)

Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

I have mixed feelings about this. Part of me thinks "who cares, character escaping has no meaning outside of a string anyway", and part of me thinks "surely they could use something better". But could they? I don't know, I'm not a developer for the Zend parser. Is it a huge oversight that until 5.3 PHP never had namespaces at all? Yes, absolutely.

Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

I think it's ok to disagree with how PHP does this, but disagree that it makes the language "bad". But ask me how much I want to sit in this topic and argue about weak vs strong typing. (P.S. I don't, at all) For the record: PHP will issue an E_WARNING level error when the type of an argument matters and cannot by solved by coercion.

Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

PHP is a DSL for the web. I've been doing it full-time for 8 years and have maybe used recursion 4 or 5 times, usually for some type of annoying directory or XML traversal. It's just not a pattern that is needed for web development that often. I'm not excusing the slow performance, but this is an academic issue far more than it is a production issue. If you need really powerful recursive performance, PHP is already the wrong language for you.

Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

I totally 100% agree with this.

PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

*Hmmm, this topic sounds desperately familiar...

But seriously, I find it remarkable that people will complain about a language that will absolutely 100% let you implement any output system you want (the sheer volume and style of PHP templating systems alone speaks to this) - OR - skip all that overhead and just output directly. This does not make PHP bad at all. It's part of what makes PHP good.

PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

Do you mean bytecode caching (like an accelerator), or output caching?

If the former, then I don't really know how much I care about this topic. Accelerators are free and easy to run. We could argue about why it isn't part of the language but in the end, I don't think it matters much.

If you are talking about output caching then I don't know what to say to you. ANY web project with significant traffic needs caching (seed podcast #27, for example). This is not a PHP-specific issue at all.

In summary, I think you consider PHP a "bad" language in a very academic fashion. And in your previous post you were probably voted down by people like me who use PHP to "get things done".


(20) Nicely said on all counts! - Adam Franco
(21) I've seen too many PHP applications being drop and rewritten because they are unmaintainable. I don't know if this trend says something (other than it is actually easy to get a PHP application built and running... ;-) - Leonardo Herrera
(1) Well put, although with an equal amount of professional PHP under my belt (8 years), I've written Plenty of recursive functions. Of course Anything could bare to be faster in an interpreted language. - enobrev
(7) The whole point is, being it a bad language in an academic fashion, there are plenty of good languages in both academic and practical fashion, and that irritates the hell out of many people. That, and the awful amount of lousy PHP around (which is just a matter of scale, I think.) - Vinko Vrsalovic
(121) By 'a matter of scale' I mean that if everyone and their dog were writing Python or Java instead of PHP, there would be an awful lot of ugly Python or Java code around. - Vinko Vrsalovic
(2) The irritation is fine as long as people understand why PHP is popular: 1) low barrier of entry for new developers 2) came out at right time. PHP's popularity has nothing to do with it a good language in an academic sense. - Peter Bailey
(20) just a note - the implicit type conversion is not a static vs. dynamic typing issue. this can be done in both kinds of languages. - Claudiu
(1) Of course that its popularity has nothing to do with it being a good language! And that's what adds injury to the insult! :) - Vinko Vrsalovic
(2) I'm not complaining about implicit type conversion at all, when it's sensible. I guess my complaint there is that often, PHP (at least in the past) will attempt to make implicit conversions that don't make sense. - Jason L
Care to highlight a situation where the type conversion really caused a probably, or does it just bug you on principle. Because, as I said, something like array_key_exists( 'key', 1 ) WILL throw an error. - Peter Bailey
I suppose it's the magical implementation that bugs me on principle. In python there are exposed "private" functions for every single type conversion, which can be read, overwritten, or specified on any custom object class. I guess under-the-hood "magic" just unnerves me. - Jason L
Actually, I can also state this: I prefer implicit conversion only when it's used to take a value and render it to a valid subclass of the same superset. For example, a real number to a complex number. - Jason L
(1) "the implicit type conversion is not a static vs. dynamic typing issue. this can be done in both kinds of languages." Then what is the definition f "static typing"? Or are you saying "static typing != strong typing/dynamic typing != weak typing" (which I agree with)? - Max Lybbert
Bailey, just curious, what IDE do you use for PHP? - Kevin
Currently, Zend Studio 5.5. I've been with the Zend IDE for about 3 years now. I'm testing their next version (Zend Studio 6 aka Zend Studio for Eclipse) but still use 5.5 for all my production work. I think once I become a bit more used to 6 I'll port all my projects over. - Peter Bailey
There's too much freedom in PHP. And too much freedom never leads to good things. That's why I've seen dozens of php sites get re-written several times wasting money and time. Ofcourse if they were written carefully (IN PHP) they would have been ok today but having the freedom to write crap.. - Andrei Rinea
(1) @andrei - that sounds more like a personnel problem rather than a technology problem. @Bailey - terrific answer! - nickf
(2) Just an FYI, APC is actually part of PHP6 (whenever that ships). Prior to that, it's just a simple php.ini option to turn it on pretty much (why you wouldn't have this on is beyond me). - cletus
(1) you nailed down. - Mohamed
(1) I don't use PHP, and I don't particularly want to. HOWEVER, you do make a series of great points, there's nothing implicitly wrong with it. - TM.
(3) I'm in much of the same boat as you are. PHP is around and it's likely to be here for several more years to come. It's quite irritating when going through reddit/SO/etc the amount of flack that PHP gets by people who don't understand the language. All languages have quirks, and those who use it often come to enjoy and even rely on them (from time to time). Personally, I enjoy PHP because it allows me to get stuff done AND get paid - Justin Johnson
(1) - Summer Galu (xkcd.com/406) - shoosh
(4) Unpredictable parameter order may not matter while you're writing code in an IDE, but it does matter for code reviews. And reading code you're not familiar with (which includes your own code after a couple of months). And even for reviewing your diffs before you commit. "Use the IDE" really doesn't cut it. - Joe White
(2) I would say being relient on your IDE does hinder your ability to be an effective programmer, or at least I found that to be the case. Hearing the argument that an IDE's intellisense is so good that it makes up for the language's inadequacies is not a credit to the language. PHP.net is a wonderful website, but I found myself referencing it way too much. I programed PHP for 5 years and I would constantly find myself looking up some of the most basic functions because I could not remember the argument order or what the function would return because of inconsistency. - Sean McCleary
(1) @Sean "I would say being relient on your IDE does hinder your ability to be an effective programmer, or at least I found that to be the case." How exactly does that hinder one's effectiveness? Spell it out for me like I'm a 4 year old. Are you saying you weren't using an IDE therefore had to look up functions all the time? I don't like that argument either. Name me one professional Java or .NET developer that doesn't use an IDE. - Peter Bailey
While people may argue that by scale alone any language will have shit (look at java) it is not the argument. The argument about PHP's coding crap is in the fact that if you are selling a web framework/language you better be selling a good one. If ruby on rails/django was a big heap of crap out-of-the-box that is only useful if you replace everything and the kitchen sink before it becomes decent for building fairly well structured, well performing, fairly secure applications, would they be so loved? - Dmitriy Likhten
@Dmitriy while I respect the point you're making, in doing so you are completely ignoring the individual histories of the tools/language involved. PHP didn't set out to be what people used it for when it was launched - quite dissimilar to RoR. And really I'm of the opinion that this topic is about how PHP is as a standalone entity, not as it compares to parallel technologies, be them older or younger. - Peter Bailey
@Peter Bailey: We are not being sold Toyota Camry '89 edition today, because it is crap comparably. If PHP is the same we should stop it as well. As standalone PHP does not come out-of-the-box with tools like sql paramater substitutions, you gota roll your own (yes there are some out there) but things being shipped this way today compared to what frameworks like RoR and Django offer is quite inferior. My info may be a year or 2 out-of-date :( - Dmitriy Likhten
(1) Yes, PHP is inferior to other techologies out there. But this topic was never about that. Besides, any car analogy (or any analogy where you refer to a physical good) is doomed to fail. Software just can't be compared to white goods like that. - Peter Bailey
(1) @killown - Stack Overflow is a place for mature, informed, and collaborative, and friendly discussion on programming and programming topics - not flame wars. Please consider exactly what you're contributing to the community or conversation before making comments like this. - Peter Bailey
"PHP is a DSL for the web. I've been doing it full-time for 8 years and have maybe used recursion 4 or 5 times... It's just not a pattern that is needed for web development that often." I've been using PHP to build websites for 10 years, of which 6 have been full-time work, rather than hobby-jobs. In that time, I have used for and while loops recursion almost daily. You must be using a library or frame work that does the recursion for you ... - phalacee
@phalacee - You write recursive algorithms nearly daily? I seriously, seriously doubt that. Either you don't understand recursion, you work in some crazy niche part of the industry where it's common to need it, or you're using it where you shouldn't be. - Peter Bailey
@Peter: I never said I write them daily, only that I use them daily. I re-use code I've already written. The code is for traversing a directory and all sub-directories creating thumb-nails of all the images it finds. - phalacee
Ok, so what did you say that contradicts my point? First of all, you're doing directory traveresal which I specified in my answer. Secondly, that's clearly an offline task, so super high performance isn't critical. And thirdly, that's not really a web task. Sure, PHP can do it, and do as part of a web process, but another language could do it just as well - which I also said in my answer. And really, when I said "used", I meant "wrote". - Peter Bailey
1
[+170] [2008-11-21 16:30:13] Vinko Vrsalovic

All your criticisms (and some more) are valid. You are allowed and even expected to hate PHP.

But, then again, it has some benefits:

  • Ubiquitous
  • Fast (especially using opcode caches)
  • Huge community (and great documentation)
  • Works

Finally, you can overcome many if not all the downsides by writing good code you'd write in any other language. You can write solid, secure and good smelling code in PHP, which many times will run faster and be easier to host and to scale than many alternatives.


(21) I can agree with you on all but fast. If you mean fast to develop, sure. If you mean performance, to get good performance out of PHP on a large project you HAVE to use caching, and that makes things rather complex. - Jason L
Well, faster than some other usually interpreted languages that shall remain unnamed. - Vinko Vrsalovic
(5) Faster than Ruby, perhaps, but I'm not a fan of Ruby either (I do respect its goals as a language, they're just counter my own). It's slower than Python or Perl, IIRC. - Jason L
(1) This is a good answer (and upvoted), but I'd like to point out that 7 out of 10 of my complaints can't be resolved by good coding practices. ;) - Jason L
Yup, it is what it is. You get some benefits and get some awful cons. There's a reason why most well trained programmers do hate PHP, you know :-) In any case, your complaints that cannot be solved by coding practices are just annoyances, you can ignore them or work around them. - Vinko Vrsalovic
(4) "are just annoyances, you can ignore them or work around them." I would class them as more than annoyances. One of the corner stones of good software is consistency. If your language of choice is an inconsistent mess like PHP, then the chances of consistent apps being developed on it are lower. - Chris Canal
Sometimes there is no choice, but you are forced to work on a language. And in that case, you can work around the inconsistencies. Seems like I must make clear my language of choice is ANYTHING BUT PHP, well, anything no. I still prefer PHP to Brainfuck or INTERCAL, sorry. - Vinko Vrsalovic
The difference is that Brainfuck was intentionally designed to try to confuse and tax the brains of developers. Waid, that isn't different than PHP. - Kibbee
(5) "Fast" - Yes, typically computers do run fast. As opposed to manually processing information with pen and paper. As for fast compared to native machine code - no. Fast enough? For some cases, but not all. - Zombies
@ Jason -- "Complex" usually means "not-fully understood". Caching should be done on all scalable websites anyway, it is not complex when fully understood. - Kerry
" well the biggest advantage of php is it is open source" and very easy to use and implement for a beginer . well thats where other languages lag behind well in course of time we expect php to develop more consistent features. - Justin Dominic
2
[+146] [2008-11-21 18:19:24] jalf

What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.

Simple. The fact that poor programmers get very defensive about their language. ;) PHP is easy to learn, much easier than the alternatives, and once you've learned it, it's not exactly obvious 1) what's wrong with PHP, 2) how the alternatives are better, and 3) how to switch to, and learn, one of the alternatives.

And perhaps the fact that, well, what alternatives do people have? ASP? That has plenty of problems on its own, from being unable to run on the majority of webservers (Apache), to some ridiculous and overengineered design choices on its own (webforms? Viewstate? AJAX where your asynchronous" requests are intercepted and run sequentially?) Ruby on Rails? Well, perhaps, except how many webservers support it again? It's not exactly easily approachable at the moment. And it's slow. So perhaps PHP's "strength" is really that no good alternative exists. At least this is why I stay away from all web programming when at all possible. PHP sucks, and I'm not too keen on any of the alternatives either.

PHP has so many fundamental problems that it's not even funny. From the lack of unicode support, to the many implicit type conversions which often lead to unexpected security holes, to the complete mixing of presentation and... everything else, or to the default database module which doesn't (last I checked) use parametrized queries. We're talking about a language made for two things, database access and generating HTML, and which is terrible at both.

It's just a nasty mess, a language designed by people who aren't qualified, or able, to design a language. ;)


(45) +1 Spot on: "poor programmers get very defensive about their language". - JesperE
(13) @OP: I would suggest that you take a look at PHP again. Your observations were spot on as v4.x but with 5.3 on the horizon, parametrized queries are the norm and generally accepted best practice. - Noah Goodrich
Additionally, there are many fine programmers working in PHP but you can generally recognize them because they'll stand up and agree that PHP is an ugly language. However, what it does do, it does pretty well in the right hands. - Noah Goodrich
(1) gabriel: That's one problem solved then, but it's symptomatic that it took them what, a decade to get there? Now, wake me up when they get proper, consistent and correct unicode handling, will you? In the right hands, a overripe banana can be used to hammer nails. That doesn't justify its use. - jalf
(1) @Jalf: Show me how you drive nails in with an overripe banana. I agree PHP has a lot of flaws, but for all its flaws, it is also a very simple and effective scripting language that will let the general public get things done. - Sylverdrag
(7) It is not simple. You just only stumble across the complexities by accident, usually without noticing. There are other simple and effective scripting languages that lets the general public get things done. PHP is a messy, inconsistent language which lets the general public create problems. - jalf
(70) a poor programmer is anyone who needs a language to impose design patterns for them, most of these people hate PHP - Fire Crow
(1) @jalf> Your comments about alternatives are partially untrue. Both ASP.Net (via Mono) and Rails (via mod_rails) can run on Apache. - Paul
(2) But your typical $5/month webhost supports neither of thoes on their Apache setups. Which means that for the vast majority of all web development, it's not an option. ;) - jalf
You asked what alternative people have. Well, what about Java (JEE)? - Adam Crume
(3) What about it? Does it run on your average $5/month Apache webhost? If not, it's not an option for the vast majority of web development. And @Fire Crow, thank you for proving that ignorance is still flourishing among PHP developers. Presumably you actually code your websites in assembler then? - jalf
(23) +1 for "So perhaps PHP's "strength" is really that no good alternative exists." Awesome point! - Ilari Kajaste
(4) ASP has neither WebForms nor ViewState. Did you mean ASP.NET? - Joe White
(1) "to the complete mixing of presentation and... everything else..." As we've already established, PHP doesn't impose mixing concerns. If mixing is an issue, it's because the developer didn't understand separation of concerns. And PHP includes a variety of libraries for properly parameterizing queries. While I agree PHP has it's faults, your tone is poor and outside of your point on Unicode (which is coming in PHP6) your facts...well, aren't. - Cory House
+1 "poor programmers get very defensive about their language" - this is the highlight of the day (maybe year) on SO - kizzx2
"by people who aren't qualified, or able, to design a language" -> Then THANK GOD that they didn't have to ask anyone for permission and just did it. - user347256
3
[+108] [2008-11-21 16:36:01] Brian C. Lane

In addition to the above, PHP's documentation is very good. http://www.php.net/rand and you go right to the documentation page for it, as well as tons of user contributed notes.

PHP is by no means perfect, but it does get the job done and its class system is better than some of the competition.


PHP's documentation is easily the best thing about it. - Chris
(3) Alright, that's an answer I can get behind. The docs are good. But I'm curious; what about the class system is better? I recall it being rather short on features. Functions aren't first-class, IIRC, and you can't inherit from built-in data types, just to name a couple of shortcomings. - Jason L
Compare it to Perl's system :) - Brian C. Lane
The function docs aren't bad, but the same can't be said about pear's. Yeah, not directly a part of php, but the extent that 3rd party libraries are supported still reflects on the language. - Dana the Sane
(2) Brian, what Perl's system? - Leonardo Herrera
@Dana: PEAR is essentially an officially-hosted library repository. If they added "requires complete documentation" to the requirements for releasing there you might find it picks up but submissions would drop right down. - Ross
(33) Really? My biggest complaint about PHP was the documentation. I found that the examples were often using so many shortcuts and tricks that to understand one example, I'd need to look up 5 more functions. The documentation is well-organized, and there's plenty of it, I just dont find quality in it. - nerdabilly
@Ross Understood, but that's kind of an indication around the community. There's some really key code on pear, and it seems like an awful lot of it is deprecated but the replacement isn't done. - Dana the Sane
(19) I couldn't agree more, PHP's documentation is one of the best things about it, not because of the documentation per se, but because of the stellar, hand picked comments & real world examples of the code. - TravisO
(6) I agree with nerdabilly - The documentation is not just poor but in some cases plain wrong: php.net/manual/en/function.date.php you can't call date() multiple times in one function - the date changes at midnight and many of these examples would come up with a wrong date/time combo, and when I posted that observation they deleted my posting! - jdkoftinoff
(1) +1 When working in PHP, PHP.Net documentation is my first choice. In .Net, MSDN documentation is my last choice. - Cory House
4
[+99] [2009-10-12 21:43:00] Gustavo Carreno

Ok, let's use a nice car analogy to understand the complete pointlessness of this discussion:

Title: Defend cars, prove me they aren't horrible.

  • Cars kill more people than any other means of transport.
  • Car's engines are very old technology, we haven't even got 100% outta them yet.
    • Not even 70% for that sake.
  • Cars have been on the list of the most harmful things to the environment.
  • Cars have been the victims of poor design, only a few years ago did they invent the seat belt, and don't get me started on the air bag...
  • Cars have a loony behind the design process, they don't agree on the shape, the colour, the braking system, the transmission (rear/front/both), the gear system, the fuel they use and I could go on and on and on...
  • The guy that invented the 3 pedals for the controls deprecated loads of other more "sensible" ways of control, like mind reading.
  • Cars have this thing called extras that most vendors seam to make profit on, what's that?!?!?
  • Cars have so low security that almost anyone can jump start one. That's very bad for the beginners. I think....
  • If you sleep behind the wheel of a car it will crash. How did this creep into the design of this tool?
  • If you don't buy one of those extras that the salesman was offering, the car will not fulfill it's intended goal, take you from point A to point B. You could find yourself on point P.
  • Most of the users of a car are very lacking in skills. They drive like maniacs and think the road belongs to themselves. That makes for very poor usage of the car.

Ok, I think you get it.

So... with all this against them, all this long, harmful, unattended, stupid and nonsensical development in this tool, how the heck is it so popular?

Probably because you wouldn't use a bathtub to get you from point A to point B. (The point is having a tool for each job)
Probably because, even if quite full of problems, it's easy to use and is the one with the most support. (Repair shop at every corner, wide spread means of refueling)
Probably because there is a very low entry barrier to hop on board.

Either that or, like Asterix always says: "These Romans must be mad!"

Wouldn't you agree?


(25) What an awesome analogy! - Ilari Kajaste
don't have to be so harsh, PHP is just a humble language - pop850
(9) In the analogy does PHP represent cars or do cars represent all programming languages? Is this a defense for PHP because both it and cars are popular? If PHP was a car, it would be a very strange amalgamation of many cars without much thought for consistency. - Sean McCleary
(19) I agree. Cars should be banned. :) - Christopher Creutzig
Your answer is a joke, right? What really scares me is how many people up-voted this answer and the "awesome analogy" comment. - kirk.burleson
(1) @kirk.burleson Yes, my answer is a joke. A joke/analogy that you can use to defend what ever you want. So I'm not saying it's good, just that a good/bad analogy can make anything look good/bad :) - Gustavo Carreno
(4) @Sean McCleary, 100 times upvote! - topright gamedev
(3) @kirk.burleson What's real funny is that there is a very good and non-scary reason for upvoting this answer, it points out the distinction between an irritation by academical disagreement and a flaw of usability by impractical design, something that in my opinion is very important to keep in mind while taking part in this (kind of) discussion(s). (And if you won't buy that, I guess 42 people just had good laughs at the joke.) - Pelle ten Cate
(3) The analogy would be more accurate if PHP was a particular model or brand of car. PHP is a lot like a Toyota RAV4 poor handling, hard to park, can't off-road at all and a lot of bad drivers. I think it's more like microwave food though, easy to cook, but tastes bad and gives you health problems. - Keyo
(1) Why the straw man argument? - Billy ONeal
(2) I think the analogy is totally groundless, but it makes a good point: PHP development should be illegal without a license. - intuited
"you wouldn't use a bathtub to get you from point A to point B" love it! :) - Ramin
5
[+59] [2008-11-22 00:50:45] ceejayoz

PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

Yes, this is annoying. However, anyone who's doing serious development in PHP is going to have them memorised quickly, and what's not memorised is very easily found in PHP's online documentation. I don't feel that this inconsistency slows me down at all.

The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.

Only if they upgrade unwisely. PHP4 didn't end-of-lifed until three years after PHP*5* was released. Three years to transition to a new version is plenty of time to fix things like that, and deprecating crappy ways of doing things is important to the rational evolution of a language.

Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

Backslash is used universally for escaping within strings. It has no meaning outside of one. Again, this is the sort of criticism that is meaningless after a few days using the language.

Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

I can state categorically that I have never, ever had a problem caused by accidentally turning an array into an integer.

Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

Can't personally speak to that - I haven't seen or performed benchmarks. I don't use recursion much at all, though.

Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

PHP'll throw an error if you try to redefine an existing function, so what's the risk here? What ambiguity is introduced here - can you offer any concrete examples?

PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

One can write crappy code in C++ or Java, too. I find the ability to do this a positive feature of PHP, too - if I were to choose a programming language to teach a six year old basic programming, it'd probably be PHP. Yes, the ability for anyone to pick up some PHP has led to a lot of bad code out there, but I consider more people having the opportunity to learn to code a good thing.

PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

Your last, and least compelling. So what? There are a variety of non-commercial caching products for PHP. You have options, and there's no reason the maintainers of PHP shouldn't be allowed to try to profit off their expertise. You're best off paying for a Windows and Visual Studio license to develop in .NET, but no one rational bashes the platform based on that.

These are not your reasons for disliking PHP. These are your excuses for not even giving it a chance.


Could not have put it better myself. - Kevin
(2) Sure, here's an example. It's fairly common in object-oriented languages to have a class definition be title-cased (e.g., Thread) and an instance be lower-cased (thread). In expressive languages, function factories follow the same convention (e.g., tostring = ToString(...)). - Jason L
(4) Also, regarding the "not giving it a chance", I programmed in PHP for years. Granted, this was several years ago, but I walked into the experience thinking, "Awesome, a cool new web language!" and left that experience vowing to never use it again unless I was starving and only PHP was paying. - Jason L
(1) Everyfuckingbody uses dot (.) for namespace "dereferencing". But noooo... they had to choose the lame backslash... Ofcourse you can ignore this but all these small ignorements add up and barf you go.. - Andrei Rinea
(3) Dot was already taken for concatenation, so that wasn't an option. Since php, js, and java came out the same year, there wasn't a consensus yet. I'm sure if they decided to start from scratch, they would follow the current norms. - Cryophallion
Upvoted because of the last line! - Jeroen Huinink
I humbly submit that you consider Python as a teaching tool for youngsters. It's probably easier to learn, having a good REPL and some consistency, and tends to encourage better programming habits and strategies. - intuited
6
[+57] [2008-11-25 01:03:59] staticsan

I think before you can be convinced that PHP is a language worth keeping around, you need to recognise that the objections you have to it are just not obstacles to people who use it everyday.

At it's core, you have a language that provides an execution environment that is easy to setup and easy to begin to use. The language itself is highly orthogonal, which makes learning it easy. It does not come with a framework That You Must Use, or and IDE that is essential. It does not have a separate compile step. All this means you have a language that does what it does and gets out of the way. For programmers, this provides an almost blank sheet of paper to go off in whatever direction they choose to build what they need to build. The language is flexible enough that there is often a variety of ways to achieve the end-result, some better than others, but others are just one amongst equals. PHP makes things like strings and hash-tables first-class objects and provides a generous array of tools to manipulate them. There is a wide-range of built-in libraries and there is a wealth of third-party code to supplement this. In addition, it has all the tools and features to scale to massive massive websites on huge databases.

Some of its current problems are as a result of the language being forced to "grow up" as thousands (if not millions) of developers make it do things the designers never even thought of, let alone thought possible. Fixing these requires a slow and careful migration so that you pull along the bulk of the developers. Notice that it took some effort to get people off PHP v3 in the last two years - and v6 is just around the corner!

It is possible to write high quality code in PHP, with clean interfaces, good separation of logic and so on. The problem is that the average quality of PHP programmer does not reach that high. And you can't force them to be better -- because that simply doesn't work. They have to learn how themselves. If they are capable of learning. I've seen PHP programmers who are just incapable of getting beyond their current mediocre level.

PHP has a lot of warts, but it is effective and widespread. Just don't get hung up on what it does 'wrong' -- most PHP programmers don't and don't need to.


(7) Although I am anti-PHP I must salute your objective and clear comment. - Andrei Rinea
*answer not comment :) - Andrei Rinea
"I've seen PHP programmers who are just incapable of getting beyond their current mediocre level." Trust me not a problem limited to PHP programmers. - HLGEM
"I've seen PHP programmers who are just incapable of getting beyond their current mediocre level." This is very prevalent with web programmers in general. - kirk.burleson
Yah, I said "PHP programmers" partly because that was the context of the question, but also because the ones I was thinking of knew only PHP. But yes, there are many programmers who will never be more than mediocre, and not just in web programming. I've met some in other areas. - staticsan
(1) I'd upvote this... except the vote count is right now at 42... - JavaAndCSharp
7
[+43] [2008-11-21 16:34:46] Noah Goodrich

Any tool, in the hands of an amateur, can become dangerous. So I wouldn't blame PHP for what people do or don't do with it, despite its apparent flaws.

PHP can be used to develop secure and robust web apps that are just as well designed as anything written in .NET, as long as you know what you're doing.

Perhaps the equally relevant question to ask is what language would you consider superior?

In my office we use PHP because of the low overhead in getting started with it because we use a LAMPP stack where everything FOSS. Running on a Microsoft platform would run my company into the ground. So I guess one valid reason that companies go with PHP is because its FOSS.

The other reason that I've seen others point out is that it gets used by many individuals for their own personal projects, and as a way for them to enter the world of web programming. I personally don't see anything wrong this. Everyone has to start somewhere, and no one is born writing beautiful code. Its something that we all grow into.

I think that other languages discourage what you might classify as bad practices by their very nature which is something that PHP doesn't do very well, but I wouldn't discount the language out of hand.


Full disclosure: my language of choices for web apps is Python, using Django. It has its own flaws, but a lot to recommend it. But to directly address your answer, 7 out of 10 of my complaints cannot be resolved by good coding practice. Do you consider those 7 complaints irrelevant? - Jason L
(3) No, PHP is definitely a red-headed, ugly step-child of a language. I don't know there's any justification for its eminence in the web development considering that Python and Java are also used for web development are probably both more elegant than PHP. - Noah Goodrich
(4) I work with PHP (Symfony), Django and Java (Echo2) and, for a basic content driven user facing site Symfony is the easiest. Django is more powerful but time consuming. Java is great for web apps but tricky for the basics. For some things, and despite it's flaws, PHP "just works". - Colonel Sponsz
Please don't make this a proprietary vs FOSS argument. There are FOSS alternatives to PHP. - Jason Baker
Pretty nice answer gabriel1836. However it takes me hard effort to understand how .NET would drive your company into the ground.. There are free tools for .NET : Visual Studio Express - free (including commercial use) Cassini Web server (instead of IIS) etc. - Andrei Rinea
@Andrei: I was under the impression that the VS Express products where only good for non-commercial use. If we could use .NET products for free in our office then the biggest downer would just be retraining staff and the fact that I personally despise anything Microsoft. - Noah Goodrich
@gabriel1836: A license for Server 2003 Web Edition (the last one I bought) costs roughly $500. It comes with everything you need. If you don't have that kind of money to spend on web server software, then your company has other problems that it needs to fix first. - Mark
8
[+37] [2008-11-27 18:05:37] community_owned

The bottom line is that PHP is (like every other language) nothing but a tool. Every job has a tool that suits it. PHP is greatly suited for quick, agile tasks that need to be done NOW.

In the real world, unfortunately, managers run the show. If a client needs a contact form, I can bang that out in 30 minutes using PHP (and even design it "properly" using an MVC architecture). Or, if I was a novice (and I say that in a loving way), I could wite the same form using ugly code, that works just as well.

Now, I started hating PHP after using it for several years for a few of the reasons listed above. Mostly, I disliked it's OOP implementation and hated the fact it was case insensitive.

As I look back on it though, I think the major problem isn't the language, but inexperienced programmers who are hired to write in it. It's the "cleaning up spilt milk" problem. About 90% of the legacy PHP code I've had to alter or maintain has been TERRIBLY written. It's not the languages fault, it's the inexperienced (or lazy) coder's fault. They took the hammer (PHP), and instead of simply driving a nail into a wall with it, they cooked spaghetti with it (successfully).

These days, I have been writing code in VBScript and Perl (NOT by choice, but gotta make a living). After working with those two nonsensical and disheveled languages, it really put PHP into perspective for me. I MISS PHP. I didn't realize what I had till I lost it. Ever try to get the size of an array stored in a hash reference in Perl? I did. Took 2 hours and I didn't solve the problem. I was forced to do a hack. In PHP, I'd simply use count() and TA DAH! There is the size of the array (which is actually a hash in PHP but that's out of the scope of what I'm trying to say).

Does the language need improvements? Yes. Does the language have a poor governing body? Yes. But what are it's strong points? It's pretty simple:

  1. EXCELLENT documentation
  2. Quick turn-around time for development
  3. A familiar, C style syntax

So in reality, It's not the language itself that's absolutely terrible, but the ironic fact that it was designed to be so quick and dirty to develop with, that it attracts poor programmers with poor programming practices.

It's ease of use is a double edged sword. It allows you to quickly write good code, just as easily as it allows you to quickly write bad code. So don't blame the gun, blame the guy who pulled the trigger.

But I'll tell ya one thing, If I had a choice between writing a web app in Perl through CGI, or using PHP; I'd use PHP in a HEARTBEAT.


(5) I agree with you in comparing Perl/CGI with PHP. However, regarding "don't blame the gun, blame the guy who pulled the trigger" if there are triggers all over the place you must be uber-careful where you step.. - Andrei Rinea
(2) While I admit that Perl is neither pretty nor "easy", I would hardly call it nonsensical. I thought to myself "Hmm, that sounds interesting, the size of an array in a hash reference. Well, you deference the hash pointer with -> to get to the array (Simple enough, any undergrad should get that), then use it in a scalar context, which is the common way to get the length of an array. Well it must be more complicated after all his complaining..." So I tried it, and guess what: $hashRef->{"MyArray"} yielded "5" just like it was supposed to. Simple? No. Logical? Absolutely. - Jax
(5) "So don't blame the gun, blame the guy who pulled the trigger" PHP: the AK47 of web languages. - philistyne
(1) People forget that php replaced perl/cgi as the dominant UNIX environment. It wasn't ever competing with JAVA, .NET, ruby, or python. It just had to have an easier syntax than perl - Bryan Waters
9
[+28] [2008-12-31 05:20:40] community_owned

PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

PHP exposes the function signatures of all the low-level libraries that it uses. Do you make this same complaint about C or C++? You should because those are the same function calls and libraries. You have the freedom to develop whatever abstractions you want over top of these low-level calls -- you aren't limited a specific high-level toolkit.

The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions.

They depreciated call time pass-by-reference which no other language has ever had. Regular pass-by-reference still exists and always will. I feel bad for the PHP developers, they try and improve the language and still get dumped on because some people don't know how to read.

Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

Agreed. But that pain hasn't even been released yet. Lets hope they change their mind. If anything, this particular issue has got me looking into alternative languages. But I have a lot good object-oriented code written in PHP that it's hard to change.

Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

I've got hundreds of thousands of lines of code in PHP and I don't find the implicit conversions to be a problem. It will not happily attempt to magically convert an array to an integer (unless you explicitly cast it).

Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

I'll give you this one; but if you're written complex algorithms in PHP then you're using the wrong tool -- plain and simple. PHP scripts aren't designed to run for long periods (in fact, the shorter the better for responsiveness). This is like complaining that you SUV uses to much gas or your Smartcar doesn't have enough room for 2x4's.

Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

They are case-insensitive because HTML tags were, at one time, case-insensitive. But your argument is stupid. If functions are case-sensitive, you're still introducing ambiguity: now you have a function named bob() and Bob() that do two entirely different things. In PHP, that sort of madness isn't allowed. If you want consistency in naming, be consistent. PHP doesn't stop you.

PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

This is entirely wrong. It does not practically require coupling processing and presentation. I've been coding in PHP for decades and while I did start by making them together (everybody did -- I came from classic ASP which does the same thing).

I think of PHP's functionality in this regard as the same as Python's immediate mode. You can fire up Python in a shell and just start typing commands and getting results. PHP is a web based languages, so this is it's equivalent of that functionality. When I need to quickly test something, I can bang out a quick script instantly and don't require bringing in a big framework (as I would with any other language) to get a result.

PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

Abysmal? Please. Take your exaggerations elsewhere. PHP is plenty fast enough without caching for 99% of what it's used for. For that remaining 1%, there are plenty of free code caches available (I use e-accelerator) and it will be included as standard in PHP6.

Are we done with this tired topic now?


"They depreciated call time pass-by-reference which no other language has ever had." VB has it! x = foo(ByRef bar) passes bar by reference even if declared as ByVal in the function. - svinto
10
[+26] [2008-11-21 16:22:42] zaratustra

If you have a problem in your application, you can always find someone nearby that knows PHP.


(35) And after they added their code, you now have two problems. ;) - jalf
(11) And then a third one comes in and says he/she needs to re-write everything... - Andrei Rinea
(2) ya the fourth will advice you, to change the framework at all :) - martani_net
(1) ROFL. so true. when someone writes something in php and it gets to me. for the life of me i cant figure out what the hell the guy was thinking. but one problem i have is i cant find anyone nearby who knows php rather than the forums. all i can find is asp.net people. and anything made by microsoft that is forced to operate on a windows i am against. - SarmenHB
(4) Every PHP developer has a different way of doing things. I think this is a good thing and a bad thing. The problem is that very bad developers can get something to work as well as a very good programmer from the perspective of a client, who doesn't see code but the front end works fine. I often get work to update existing PHP project and I'm astounded at how bad the code is. The client ends up paying double since half my time is spent fixing old code. - wmid
11
[+22] [2008-11-21 16:32:34] Mischa Kroon

The huge pile of

  • open source projects that run on it.
  • people who use it
  • jobs to find
  • cheap hosting providers that support it
  • ...

But for the language itself, it's sort of dynamic with decent performance? (best I can do, sorry PHP)


I think "easy to find jobs using it" is a valid point. We all have to eat. ;) - Jason L
(1) I don't think any of those are specific to PHP, though. I can say the same thing about .NET, too. Granted, there aren't as many open source projects, but there are quite a few. As for the jobs aspect, the lack of competitive pay is the reason I changed platforms when .NET came out. - joseph.ferris
1. Jobs easy to find, lower wages 2. How much cheaper is PHP hosting compared to .NET? 20%? - Andrei Rinea
(3) @Andrei: True on #1. Too many PHP jobs are not really programming job. The employers often want someone cheap who knows a bit of everything (HTML/CSS, PHP, JavaScript, Flash, Photoshop), but don't know anything really well. - Imran
12
[+21] [2008-11-21 21:06:23] Richard Levasseur

I wouldn't say PHP is a bad language, but an ugly language. There are many impoverishing things about it compared to other languages.

Inconsistent function names, no name spaces, subtle, frustrating type conversions, poor iterators, and lacking lots of cool features other languages have (threads, python generators, python object model, perl ~=, java object persistence layers, inherent pass by reference for non-primitives, etc).

However, I would argue that a major reason it is so popular, so useful, is precisely because it doesn't have those features.

An example: How many times have you seen a loop over database results several times in a web app? Loop to fetch from the database, loop to convert it to application objects, loop to apply special formatting, loop for a few hacks, loop to display. And in php, you're probably copying the array for each loop.

Thats a lot of looping. If you use generators, you can preserver all that looping and eliminate all of it. But now you've introduced a fairly complicated concept, one that needs to be understood fully (much like threading must be).

While I don't mean to speak ill of web developers, the majority of them aren't the cream of the crop. Introducing complexity like a generator will at best make no difference, at worst, do more harm than good.

With that said, it has some good reasons for sticking around: its very easy to understand, its pretty much everywhere, and it has strong library support. Those mean a lot when you need to make something and make it fast, which almost webapps need to do.

While you say that it promotes bad design and coding, I would say thats more the nature of web development. Too many times I've seen something simple have crazy, from a software perspective, requests made of it. To the clients, these request aren't crazy. They want VP's to not require validation, or anonymous access to be moderated, or a certain use case to display a special message, or some strange integration for a specific use-case.

My point is, a web app is custom glue code. It glues everything together, just how you want it, and its going to be ugly after a few iterations.

Anyways, my flight is about to board, so in a nutshell: PHP isn't a bad language, but its impoverishing when you need to do some really neat things the right way.


(4) Wow, as if all the people trashing PHP wasn't bad enough, you decide to go after an entire group of programmers. Elitism doesn't serve anybody. Yes, PHP is easy to learn, and doesn't look very pretty. It can also create excellent applications with a decent programmer behind it, like any language. - MattBelanger
(4) But that doesn't invalidate his point. If a language's main feature is that it's simplistic at the expense of power and "correctness" (from a design perspective), it's valid to point out that its supporters are going to tend to be "lesser" programmers in terms of knowledge and talent. - Jason L
Blanket statements are ugly - Joe Philllips
(5) PHP gets a bad rap because of its availability and shallow learning curve. Yes, a good programmer can make some incredible, secure, fast applications with PHP, but a novice with minimal skills can figure out the PHP basics within a few days. It also helps PHP is offered by 99% of hosting providers for $4.99 a month. - wmid
(2) Visually, PHP is the most beautiful language. It's short, concise, and readable. Plus the dollar signs stand out so it's easy to skim through and find variables. The same couldn't be said of wall-of-verbose-text Java. - Lotus Notes
(1) PHP "scripters" are definately "lesser" programmers. I've met more than a few who think they know C because they program PHP. What morons. And yes, most web programmers are way below standard. - kirk.burleson
13
[+20] [2008-11-21 16:45:34] TravisO

Every point you make about PHP is correct, but the alternatives aren't silver bullets either.

In strongly typed languages, such as C#, you spend a lot of time casting your data types for use in various objects. In 99.999% of apps written, the efficiency that strict data typing offers doesn't matter. Most of us are writing CRUD apps, and the only bottleneck is poorly written SQL code.

PHP has it's merits for the some of the reasons why VB6 was so popular (well without the stellar IDE), anybody with a head on their shoulders can attempt to write an application, and do it fairly quickly. Good devs can write good apps, bad devs write bad apps, but at least they still work.

You need to spend less time worrying about camel case vs underscore separated functions and provide solutions to your customers (or company). Excuse the lure of a car analogy, but I really don't want my mechanic telling me how my Nissan values are coated in iodized aluminum or plated alumnium. In the grand scene of things, PHP is far from a bad language. It fills a very important niche that fuels a large part of the web. And somebody who is focusing on trivial things to decide their platform are worrying about unimportant things.

I code in both C# ASP.NET and PHP, but when I start personal projects, I almost always choose PHP because the ROI of my time is much greater. The only time I prefer C# is for desktop applications (for obvious reasons).


I'm not whining, I'm asking for an honest opinion from seasoned PHP users/lovers. I don't use PHP. I haven't used it in years. Thanks for playing. - Jason L
(8) "such as C#, you spend a lot of time casting your data types for use in various objects." Errr, no you don't! You might want to look into generics. - Chris Canal
I'm not worried about Camel case versus underscored. I'm worried about a language that thinks a reference to MyToken and a reference to mytoken are equivalent. I'm worried about a language where half the built-ins are Camel case and the other half are underscored. - Jason L
(6) Sure, I don't want to be concerned with the coating of my car's valves. But my car's engineer sure as hell should be. And you'd better believe that your mechanic cares too. I'm not debating PHP with my employers, I'm trying to discuss it on a discussion forum. Why are you so dismissive? - Jason L
(1) "such as C#, you spend a lot of time casting your data types for use in various objects." That's not how I program. - Max Lybbert
(1) uch as C#, you spend a lot of time casting your data types for use in various objects - wrong - qui
and don't spend too much time on Data Access Logic. Use LINQ to SQL or other O/R-M (NHibernate?) - Andrei Rinea
(2) Bzzt, wrong. Strongly typed has nothing to do with casting. Python has a strong type system and it has no cast operator at all! Also, using a statically typed language doesn't mean that you have to spend a lot of time casting. Haskell is a statically typed language but the compiler does type inference for you and typecasts automatically. Even C# has generics, which eliminate 99% of all the places I would use casts in my code, and the var keyword, which eliminates most of your type declarations too. - Daniel Pryden
14
[+14] [2008-11-22 02:32:45] Ali

A couple of people at my university were talking about how bad PHP is recently.

My opinion is that anyone with any knowledge of other programming languages shouldn't even be wasting their time talking about how bad PHP is, they just should use something better and forget about it.

However, I also take slight issue with completely writing off PHP as I only entered my programming career through PHP.

This may sound absolutely mad, but to me PHP almost fits into the same category as C and Lisp as being a language that more or less nails what it is trying to do in a fairly in a fairly fundamental way.

My explanation to them was simply: "PHP went down the simplicity road from C and I think it stopped at more or less the right place."

Edit: When you look at the bad code from PHP programmers, you are looking at the code from people who didn't graduate to bigger things, is it really surprising that they write poorer code? Even for the people who did move on, you are still looking at their first programs, before they learned better programming ideas. I can tell you, my PHP code written after learning Lisp is indistinguishable from the code I wrote a year ago in PHP.


(3) The problem is that PHP does not nail what it was meant to do. It was meant to access a database, and produce HTML. And it sucks at both. Database access typically without parametrized queries, and (x)html in a language which doesn't support Unicode? And where you manually have to escape everything - jalf
(6) @Jalf - your database complaint is all about the programmers using the language, and has nothing to do with the language itself. You can write insecure code in any language - MattBelanger
Yeah this answer is defending PHP because its pretty good at being simple IMO, nothing more. - Ali
(2) The existence of mysql_real_escape_string speaks volumes not only about the security of PHP, but also about the joys of having completely different APIs for accessing different databases. Thank god for PDO. - Kibbee
@mabwi: Wrong. A language that advertises itself as being simple for new programmers to use should be protecting that user from the most glaring mistakes of usage. I would assume this is why PHP doesn't, for example, require memory management or expose pointers. - Jason L
There is a difference between 'simple' and 'simple for new programmers'. His examples, C and Lisp, are both conceptually simple -- but neither are considered simple for new programmers. - gnud
Just because you don't use PDO doesn't mean that PHP sucks at accessing databases. - Lotus Notes
15
[+13] [2008-11-21 16:19:21] Vincent Van Den Berghe

It's free!

Oh wait...


(9) ... and worth every penny! - Bruce Alderman
(3) ... not a penny more. - Brad Gilbert
(4) Free as in Zend Accelerator. - Andrei Rinea
Other languages are also free to code but not free to host. That is the main difference with the word FREE. They are all free to code but not to serve. - Codex73
(2) Andrei: APC. Xcache. Eaccelerator. - David Caunt
16
[+13] [2008-12-08 18:39:09] lo_fye

I'll start by saying "a great developer can build quality software in any language", and "there are a lot of not-great php developers"...

PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

Sure, but any language that evolves runs into these kinds of issues. They're easily resolved by using an IDE such as "Zend Studio for Eclipse", which will auto-complete things for you, and hint at the right order for parameters.

The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.

Python just launched version 3 of itself, totally breaking backward compatibility. At least PHP took a long time to do it, and they still support the 4.x branch that does it the old way.

Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

I agree that backslash was a WTF moment.

Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

It can be very handy sometimes, and it can bit you in the butt at other times. The key is to validate or typecast your data before you use it.

Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

I've never had a problem with it... of course, I've probably only used it once a year over the past 10 years. Most small-to-medium sized web apps just aren't complicated enough to require it.

Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

Most people I know are case insensitive, too. They can parse ALL CAPS and all lowers, and MixEd.

PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

I totally disagree, and I'm sure everyone at www.smarty.net would disagree, too. There are lots of templating systems written in/for PHP... BUT you have to have discipline when you use them. I would argue that being a good PHP developer requires more discipline than it does in many other languages specifically because PHP affords you so many opportunities to "do it your way".

PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

PHP runs a lot of sites, and most of them don't use caching. I don't think it's as 'abysmal' as you say it is.

Worst of all, PHP convinces people that designing web applications is easy.

That's your "worst of all" ?? I think that's a great thing. It gets more people interested in computers & programming in general. It's a great "gateway language" that could lead to more hardcore languages in the future ;)

designing a web application that is both secure and efficient is a very difficult task.

It's a difficult task in any language.

By convincing so many to take up programming, PHP has taught an entire subgroup of programmers bad habits and bad design

Your premise is flawed, good sir. Convincing people to take up programming is entirely different from teaching bad habits & bad design. Either of those things can and does happen with any language.

It's given them access to capabilities that they lack the understanding to use safely.

How many Americans own guns? How many of them have had "firearm safety" training? How many of them think it's their right to own a gun, regardless? It's up to the person to understand the safety requirements of the tools they choose to use. It's also up to their employers to hire people who are trained & certified.

This has led to PHP's reputation as being insecure.

The sheer volume of "php programmers" has helped that, too. I'm sure the percentage of python & ruby programmers who "suck" is similar to the percentage of php programmers who suck... it's just that there are so many more php programmers, that the same percentage yields a much higher volume. Of course, it also means there are more awesome php programmers... they're just harder to find floating around in a sea of n00bz.

What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language

Ahhh, organically-grown. So ripe. So tasty. I think you've hit the nail on the head right there. As soon as a fad hits the net, there are 10 PHP classes for accessing it, modifying it, and remixing it into your own monkey. Some suck, some are great. Either way they're there for you to play with, on Day Zero, and that's fun and exciting. PHP is nothing if not all about Fun & Exciting.


(2) "Python just launched version 3 of itself, totally breaking backward compatibility. At least PHP took a long time to do it, and they still support the 4.x branch that does it the old way." Bad example as Python 2.5 is not deprecated and there aren't plans to do so. - Dana the Sane
@Dana, even if it's not deprecated, I think the author's argument still stands, it does what Python does too - and nothing is wrong with that. Deprecating useless (and in PHP, most of the times, dangerous) feature is essential to make the language mature. - rickchristie
17
[+11] [2008-11-25 04:35:38] Eli

A poor craftsman blames his tools.

Sure, PHP has warts and it lacks fancy meta-programming and syntactic sugar. But so what? It's more than capable for most web applications, it's relatively fast, its flaws are well understood and it has virtually universal support.


(4) Perhaps, but a stupid craftsman is unaware of the nature of his tools and an unwise craftsman avoids discussing or pondering their assessment of that nature. - Jason L
(2) +1: More because I agree with the aphorism than the rest of the post... I wish more folks thought in this way. - TokenMacGuy
Sure, a rock doesn't have a handle, is prone to shattering, and is not shaped to allow leverage, but so what? It's more than capable for most nails, it's relatively fast, its flaws are well understood, and it is virtually universally available. - intuited
18
[+10] [2008-11-21 16:24:39] Ben

Here's what I think: ok, it's not perfect, but if you want to put something together reasonably quickly which is not hugely complex, then PHP is (in my opinion) the best way to do it, particularly if it's a web application with a database back-end. I guess the real point is that for people who know how to program but don't want to get into the complexities of Django etc., PHP is very handy.


I can understand the perspective that PHP is good enough for simple things and fast for simple things. Why do you think it is that so many people are using it for large projects? - Jason L
Well, there I agree with you. I've built a pretty large project in PHP, and while it was successful, it was a bit of a nightmare, and I wouldn't choose to go down that route again for a large project. I guess the reason people use it in those situations is familiarity and simplicity. - Ben
19
[+9] [2008-11-23 00:25:07] Prajwal Tuladhar

PHP is not horrible by any means if one consider following points:

  • Google 'PHP' and PHP related stuff: one will find results more than that of any programming language
  • PHP is open source and light weight
  • If one uses PHP for its core purpose i.e. scripting then, one won't find any significant side-effect in the language
  • Now from PHP 5, PHP can be considered as a pure Object Oriented language. There is interface, reflection, PHP Data Object (PDO) as kinda native data access layer or much like ADO.NET, type hinting and the list goes on.
  • please don't compare PHP with C# and/or Java. It's just not fair. If one only compares scripting part of these languages with PHP, it's far more easier to code in PHP.

And finally, rather than comparing languages it would be rather better to focus on using design patterns, test driven approach, object oriented doctrines and modularization concepts. Anyone can learn languages in a matter of time but once one have ideas about agile development, one can implement it in any language with ease.


That's actually really quite unfair, as every url that has .php at the end will trigger a hit, even if nobody is discussing PHP there. - DeadMG
20
[+8] [2008-11-22 01:18:05] artificialidiot

You can find a PHP job very easily, even if you are not competent, thanks to its ubiquity. Your non-programmer employer most likely expect you to be replaceable in any case. But you can thwart their expectations by writing tricky and horrible code (as in type coercion) which you get to maintain longer than they would keep you otherwise. Few languages helps you write as bad code better than PHP.


So incompetent programmers who write bad code...make PHP a horrible language? Makes sense. - Kevin
I had to upvote because the premise is entirely correct. PHP is a language where every facet of it is designed to encourage the authorship of poor code. - cfeduke
(2) @cfeduke - not necessarily 'designed to' but definitely 'promotes' - Simon_Weaver
21
[+7] [2010-09-28 15:19:59] methodin

PHP is not a bad language. It just simply does not have a large barrier to entry. Anyone can copy and paste code into an HTML page if PHP is supported, and that alone starts them down a slippery path of hacky modifications that help no one in the long run. Compare that to say, C#, and your average joe will not be able to even comprehend how to accomplish the same task.

Given that is is no wonder that when finding PHP code around the web, most of it tends to be terrible as it's easy to propagate. Case in point at my current work I have to support around 1 million lines of PHP code. 80% of it is garbage, redundant etc... written by people with no experience or teams in India. Just as with any other language a developer can conceptually understand concepts like OOP but in practice, without a lot of experience, it will always be implemented in the worst possible manner. Unlike most other languages, however, debugging this monstrosity and re-write sections of terrible code is breeze in PHP

I've written terrible PHP code before, for sure, just as everyone else has. But I've written god awful C# code before as well and in the long run, PHP was a hell of a lot easier to maintain and fix. It can be an elegant language despite its quirks. But I'll tell you what, for some reason no other language is as easy for me to implement basic things. When I want to simply query a database and display results, I can accomplish this very quickly and easily, and since I don't have to care what type the resulting array is, displaying and using this content is a breeze.

For MVC style web applications, nothing beats PHP. It can be very fast and efficient if you actually understand what is happening on a server level and know how to tweak settings. Combining APC, Memcache and an efficient database, it really can be a beautiful thing.

PHP non-strict style is an aid if you understand the language.


We're all in consensus that people can write bad code in any language. This has been argued a dozen times in other answers. Your answer doesn't address any of the points the question makes about language itself. - meagar
(3) The original post was stating facts, some objective and some subjective, and asked people to defend PHP the language - not counter every single point. - methodin
22
[+6] [2010-07-20 18:56:40] BigPat

This remind me of Galileo Galilei [1] saying: You know what guys? Maybe I'm just drunk, but what if the Earth was actually rotating around the Sun? It's the same thing. New ideas, new technologies sounds crazy and not relevant.

How old is .NET? What about PHP? ASP was a shame... The current version of PHP will maybe turn into something really awesome. AND OPEN SOURCE.

I know that most banks, government and bunker-ish websites uses .NET. But!!

Web 2.0 clearly shows a trend to PHP.

So for me PHP it is. Sorry if .NET is not my cup of tea.

[1] http://en.wikipedia.org/wiki/Galileo_Galilei

The biggest problem with PHP as I see it: Complex applications tend to become very slow very fast due to application design, which boils down to initializing the complete app and conf for each and every request while other great frameworks (in other languages), albeit the parser is slower, are much faster due to the fact spawning from a preinitialized application which handles more than one request in sequence (eg Rails, Django, ...). Is there an php equiv of that? - hurikhan77
@hurikhan77 Does opcode cashing count? - George Marian
+1 I truly agree with the "PHP will maybe turn into something really awesome..AND OPEN SOURCE." - Unknown
PHP 14, indeed, may be the next big thing;) - el.pescado
BTW, in PHP there are almost no new ideas nor new technologies, there are mostly reimplementation of existing features (of various qualities). Pardon, I forgot safe_mode, magic quotes and register_globals;) - el.pescado
This answer deserves more upvotes - Mark
What about other languages? Rails? - intuited
23
[+6] [2009-07-16 16:48:21] capfu

I don't object to the statement that PHP is horrible. It has a lot of problems which were all mentioned in the question...

...BUT

  • has all the features you'd expect from a C/C++ heritage (it's very familiar)
  • it's free
  • very easy to learn
  • lets you quickly produce results
  • is extremely well documented
  • has a HUGE fanbase and
  • got a good amount of WTFs that keep you on your toes ;-)

So if you like to program something with quick results (and if your code is clean and you plan ahead you won't get into trouble), don't have a lot of money for software licences, (and/or are inexperienced with or still learning PHP) you can't go wrong.

PS. I really like PHP and have used it succesfully for 10+ years. Sometimes you just don't want to solve a problem with the overhead of some languages like Java etc.


24
[+6] [2009-07-16 22:47:25] Question Mark

The PHP manual (I prefer the previous layout for function reference) is the clearest documentation I have ever seen, and php.net [1] for the user contributed notes against each function/topic. Genius!

It is easy to write a mess of code, but easy to look up the finer points of the language, also for an experienced programmer.

$obj = (object) array('property' => $value);

Lush, I love some of the little unused corners of this language.

[1] http://php.net/

What about the Java API? - middus
25
[+5] [2009-06-09 23:23:23] Bryan Waters
  1. It's free.
  2. It's easier to maintain than Perl, the older P in LAMP [1].
[1] http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29

+1 PERL is UGLY! - George Edison
And it was the first replacement for PERL on unix/Linux. The Java, ruby, python stuff didn't come along till much later. - Bryan Waters
Everything is easier to maintain then PERL. - utku.zih
This is an ancient post, but I just wanted to note that Python is older than PHP by years. - syrion
26
[+5] [2010-12-17 16:34:20] Mohsen

You have every right to hate PHP because in fact it has many faults but consider these too:

  1. Its learning curve is not steep
  2. Has a comprehensive library of functions
  3. Huge websites, like Facebook, are done with PHP so it has huge potential
  4. With no change or a little change code will be ready for the next version
  5. Vast amount of resources like books, tutorials, open source codes and full projects to use
  6. and many more...

If we look at it with a technical viewpoint it has some problems but software projects need more than a technical look.


Every point except 3 is applicable to most languages, and as for point 3, there are many websites built in other languages that out-shine Facebook and therefore have just as huge a "potential". None of these are points in PHP's favor so much as points in favor of high-level languages. - meagar
(1) Right but let me say why Zuckerburg did not choose Asp.net or Cold fusion for Facebook? I think because he could not afford to license those big server products therefore PHP has huge potential to be the first hand programming language for startups and open source projects. - Mohsen
27
[+4] [2010-03-16 15:15:20] rpSetzer

There are tons of high quality projects based on PHP. No matter what you want to build, you'll probably find some quality open source project to assist you. Think of Drupal [1], Joomla [2], WordPress [3], just to name a few. I think efficency and not reinventing the wheel should be the top priorities of a developer. And here, PHP wins by far.

[1] http://en.wikipedia.org/wiki/Drupal
[2] http://en.wikipedia.org/wiki/Joomla
[3] http://en.wikipedia.org/wiki/WordPress

28
[+4] [2010-07-14 20:43:58] Sane

For me it's php.net [1]'s documentation that keeps me using it. I can look up almost any part of the language and expect a clear idea of how it works and examples on how to use it.

I am yet to find any other language that has such a complete language reference in one place.

[1] http://php.net/

(5) Many other languages have documentation available. The difference is how frequently you have to go to PHP's documentation for the order of arguments or to find out whether it's 'get_class' or 'getclass'. - meagar
29
[+4] [2009-06-24 19:56:36] Robert DeBoer

I know this is probably dead and gone, but I cannot resist.

Something that needs to be remembered, and was briefly mentioned beforehand, is that you cannot compare PHP to just any language. People tend to use the term "programming language" loosely without giving it much thought sometimes I think. While all languages could be grouped as a "programming language" in a broad sense, not all "programming languages" are equal (Yes - an owl [1] and a ostrich [2] are both birds, but they certainly are very different for different environments).

A language is designed to solve a particular problem: BASIC was created to program hobby computers back in the day, PHP was created to make web pages, JavaScript to help with Java applets in the Netscape browser. Each one was created with a different purpose in mind, and so has different characteristics to meet that problem, and operates in a different environment.

Remember, PHP was designed in the beginning to be a simple language for making web pages, nothing else. So it is not going to have the same features of a language such as C++ or BASIC that was designed for computer programming, or JavaScript for client side web scripting. Yes, compare PHP to Ruby on Rails, Python, ASP/ASP.NET, but don't compare it broadly to all the other languages when they all were not created for the same purpose.

[1] http://en.wikipedia.org/wiki/Owl
[2] http://en.wikipedia.org/wiki/Ostrich

i think it is not fair to compare PHP with Ruby on Rails .. since php is language and rails is framework. Although Rails is easy, i still using Codeigniter :) simple and easy to understand. - nightingale2k1
Ruby is a general-purpose scripting language. - meagar
BASIC preceded hobby computers. - Peter Mortensen
30
[+4] [2008-11-22 05:32:43] ehassler

Only call-time pass by reference is deprecated. So you can function f(& $var) and when you call f($a) then $var and $a are the same in the symbol table. But you can't take function h($var) and f(& $a) without getting the warning. But even if it where, you can always use an object since they're always passed-by-reference.

I'm not sure how call-time pass-by-reference being deprecated causes problems for function callbacks: perhaps you are thinking of callbacks from a C++ perspective. In PHP you can call a global function by it's name such as $fname = 'func_name'; $fname(). There's also call_user_func_array() and the reflection classes to call functions and methods.

The inconsistent function naming and argument order is a pain, but an IDE can mitigate much of that unpleasantness. That said, I still get my $needle and $haystack out of order more often than I care to admit.

As for performance, let me say that I've never used PHP without the APC extension for caching. Even then, function calls and some of the language magic can really start to add up and bog down performance. But 99.9% of the projects I do in PHP are very thin layers on top of a database. When we have projects that require more complex logic and processing, we do that in C or Java. With the PHP-Java bridge or Quercus you can easily interface Java and PHP. You can also write an extension in C or C++ for PHP.

To your point of ambiguity, case insensitivity is not ambiguous, I bet you know exactly what will happen if you call my_func() versus my_Func(). Honestly, I don't see why you'd want there to be different behaviors for functions based on their case. Variables, I can see, especially for people using a lot of linear algebra or statistics, but PHP isn't really the language for those types of algorithms since it's slow.

One feature that I enjoy about PHP is that it is not strictly typed. I wish its type hinting were more robust, but if you compare the number of times I’ve made errors where type checking would have caught it in PHP versus the number of times I’ve had to go through typecasting hell, well, let’s just say I like this about PHP.

As for separating display from logic, you should check out Code Igniter or Kohana, or any of the n PHP frameworks that pride themselves on doing that.


Sorry, but case insensitivity IS ambiguous. A computer language is not a speaking language. It is a mathematical language. If you try and argue otherwise, I'd like to remind you that your computer is nothing more than an exceedingly complex adding machine. - Jason L
Now, to directly reply to your own post, you point out that functions can be used as arguments. That they can be treated as values. Then you also say you can understand it being ambiguous for variable names. If you can treat a function as a value then it IS a variable. - Jason L
A name token, be it for a variable, a function, etc, is a stand-in name for a memory reference. If I tell PHP to make a function "my_funct", then allowing a reference to "my_Funct" to access my function is a case of the compiler disregarding my specification. How can I trust such a compiler? - Jason L
"If you can treat a function as a value then it is a variable." Then values are variables, so 1 and 2.3 are variables... you live in a frighteningly variable world. Math, mind you, uses font and case to differentiate variables as well. You wanna make italics part of your language? - ehassler
Functions are supposed to specify behavior, so they should not have ambiguous names, and if you're relying on case for two functions then you're doing it wrong. - ehassler
Jason, you can trust it because you know beforehand that it will not distinguish the two. And it did not disregard your specification, you did not understand what your specification told it. - gnud
31
[+3] [2008-11-21 17:00:59] OIS

PHP has functions in C which are fast if you know how to use them. Used correctly they can do many things faster than python and perl.

PHP scales very easily by optimizing cache or adding more servers.

And once you've automated something like loading files with classes or set up a template system, building on top of it is very fast. PHP OOP is very easy to automate things fast and securely.


Just wanted to say I voted you up. You were voted down and I don't see why. My first thought is that you were the only one to actually offer your own arguments for php, and some "php only!" jerk voted you down. It's a shame when people misuse the system like that. - Chris
(1) That should be "some 'php sucks!' jerk" - Chris
(3) "PHP has functions in C which are fast if you know how to use them. Used correctly they can do many things faster than python and perl." Both Perl and Python have functions implemented in C, so I rally don't understand this statement. - Max Lybbert
"most of the standard library is cross-platform Python code" from en.wikipedia.org/wiki/… - OIS
@OIS I don't think that's accurate, see docs.python.org/library "The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers" Not a trivial addition to the stdlib. - Dana the Sane
32
[+3] [2009-07-14 08:28:58] nightingale2k1
  1. you can do things faster in PHP than in other languages (say Java, ASP Classic, etc.). I know that some people write bad code with PHP (lots of people) but AFAIK [1] some of them are not computer science people. They are just common people and they can learn PHP easily without bothering about OOP complexity.

  2. PHP is so small. You can have a portable one as well (use XAMPP [2], for example. Compare to Tomcat [3], GlassFish [4], etc. that need Java to be installed first and then set path, etc.).

  3. numbers will speak louder :D There are lots more people using PHP than other languages.

I did my projects for the past 5 years using PHP and my skill was improved by reading some code and using frameworks. I also using Groovy [5] and Grails [6] for web applications development since my client require me to use Java ;)

How about "asking" Google Trends ? link text [7]

alt text

PHP is still loved by most people. ASP.NET comes next.

[1] http://en.wiktionary.org/wiki/AFAIK
[2] http://en.wikipedia.org/wiki/XAMPP
[3] http://en.wikipedia.org/wiki/Apache_Tomcat
[4] http://en.wikipedia.org/wiki/GlassFish
[5] http://en.wikipedia.org/wiki/Groovy_%28programming_language%29
[6] http://en.wikipedia.org/wiki/Grails_%28framework%29
[7] http://www.google.com/trends/viz?q=php,+asp.net,+jsp,+ruby,+rails,+python,+django&date=all&geo=all&graph=weekly_img&sort=0&sa=N

Interesting how PHP seems to be searched for less and less. But nothing else is rising to take its place... - DisgruntledGoat
33
[+3] [2008-12-03 22:25:16] Jake McGraw
  • Yahoo
  • Facebook
  • Flickr
  • Wikipedia
  • WordPress

Good enough for you?


(2) No. Ford, Dodge, Chevy.. Great, ha? Widely spreaded... cheap and low-quality. Just like the sites you mentioned. - Andrei Rinea
(1) andrei, what are the good quality sites? (non php i assume?) - sarsnake
34
[+3] [2010-07-15 03:35:33] Aaron

I consider this debate to be summed up by whether you think a good compiler/interpreter can replace a good software engineer.

The bourgeois academic route (i.e. Java) is that the compiler should be smart enough and require so much verbose explicit-ness that it will make up for mediocre programmers who tend to make the kind of errors that a compiler can catch. That's why it's great to use on enterprise applications where you tend to have hundreds of disconnected, middle-of-the-bell-curve programmers all trying to turn out a working piece of software. All the verbosity leads to more lines of code, which tends to mean more lines to debug and larger maintenance headaches.

The PHP route is to make a language that is much less verbose and explicit, which can therefore be used for great good by good programmers or great evil by mediocre programmers. My experience has been that PHP requires significantly less lines of code than most counterparts, which means less lines of potential bugs and simpler code maintenance, especially for web-based code.

For example, PHP's double dollar sign is a beautiful piece of programming art which, when used properly, can reduce code size very significantly. When used improperly, it can create bugs that are very difficult to track down.

However, PHP code without a programmer-specified coherent structure and framework is to programming what atonal composition is to music: easy to write and impossible to enjoy.

The only important factor, in my opinion, as to the "horrible-ness" or "great-ness" of a programming language is does it make your programming team and their projects more or less productive and/or buggy. Usually the answer depends on your team and/or project.


35
[+2] [2010-07-14 12:30:11] Ben Dauphinee

The one reason that I started with PHP and still like using it is that the documentation is there. The manual has every core function documented (sure, camel case, weird underscoring and argument order). If I want to know how to use something, I can find out in a manner of seconds. I've been working a bit with Perl lately, and I find it very frustrating at times because the documentation is less... easy. Not to bash Perl, because it is awesome when you know what you are doing, but PHP is the best documentation that I have found in any language I have tried to pick up.

There are ways to mitigate most of the things that can be perceived as problems, and there are some very awesome projects out there that can make even the worst code better (Zend Framework being one).


36
[+2] [2008-12-16 03:40:03] community_owned

It does a good job making it easy to create dynamic markup. I'd rather read naive PHP rendering code than something where all the markup is locked up in non-syntax-highlighted strings in print statements.

It performs well in a default install, in contrast to most other things.


37
[+2] [2009-03-01 10:15:27] raspi

One of PHP's biggest problems are novices who can't take the time to do validation, etc. and this leads to security problems which causes a bad image for PHP in the long run. It's a bit too easy. In one forum there were same time topics titled "Python: How I can handle errors?" and "PHP: How I can hide errors?". Pretty much sums it up. People just glue PHP applications together and then go with it.

As a PHP programmer and hosting provider myself for 8+ years I'd say PHP's good points are its vast collection of libraries and classes and that it's fast. I can run hundreds of small pretty busy sites compared to Java based memory and CPU hogs. I've looked into Django and Ruby on Rails but libraries that you need just aren't there.

I've also seen that PHP is fading but frameworks like Symfony [1] and Zend Framework [2] may be these future saviours of PHP.

[1] http://en.wikipedia.org/wiki/Symfony
[2] http://en.wikipedia.org/wiki/Zend_Framework

38
[+2] [2009-10-12 20:48:37] gargantaun

From a personal point of view... If it weren't for PHP, and its forgiving nature, I wouldn't be a developer at all. I never studied comp-sci or development, I didn't think I'd ever become a developer, but I'm a designer, the web became what it is and development was a skill I needed to learn in order to survive.

It's quick, dirty, easy and I love it. I now know my way around a few different languages, but I owe everything to PHP for teaching me the basics.


39
[+1] [2010-01-21 15:44:21] RJD22

PHP is as bad as you make it. If you are just programming an application without thinking it through you can't expect a good program from any language.

I think the develpoment team of PHP did a really good job creating a language that people without any initial programming experience can understand. Isn't that our goal? Having a programming language that is easy to understand for everyone?

Now let's see why PHP isn't as bad as you think. First PHP is not slow as long as you program it not to be slow. Most of the time it isn't PHP that is slow but the database engine that can't get the data faster. That is why we cache the data.

It doesn't have structure: Not true. Look at all those frameworks out to give PHP structure. Kohana [1], Yui [2], Zend [3], Symfony [4] (I leave CodeIgniter [5] out because it's supporting PHP 4 and doesn't use full OOP). These frameworks even make the PHP language better than some other languages in my opinion.

In my opinion PHP is a great language as long as you think before writing anything. And with the use of a framework it becomes a bit more of a programming language than a scripting language. For now only databases and data structures are the real bottlenecks for speed.

[1] http://en.wikipedia.org/wiki/Kohana
[2] http://en.wikipedia.org/wiki/Yahoo!_UI_Library
[3] http://en.wikipedia.org/wiki/Zend_Framework
[4] http://en.wikipedia.org/wiki/Symfony
[5] http://en.wikipedia.org/wiki/Codeigniter#CodeIgniter

40
[+1] [2009-07-16 23:05:20] TokenMacGuy

I think PHP gets some rabid, fanatical defense for the same reason most languages get this treatment. It is often the first language learned by a new programmer, and this opinion is held as long as that programmer still hasn't been forced to learn more languages.

PHP really is good enough for what these programmers are using it for, to put up a website and give it some brains. It supports enough kinds of programming that it doesn't really hinder them from expressing their code. And significantly, it doesn't look anything like the languages other folks are telling them to learn instead.

The converse of this also applies equally. PHP is strongly hated by folks that learned several other languages first. It lacks the purity of lisp. It lacks the clarity of Python. It lacks the ecosystem of Java. It lacks the performance of C++. And so on. It doesn't really offer much over these languages, for the general tasks these languages are often used. Of course, while correct, they are missing a key point. It's very easy to get free web-app hosting for your favorite language, so long as your favorite language is PHP.


So true - Apache/Linux is the tail wagging PHP's dog... - sunwukung
41
[+1] [2009-07-24 21:33:23] MidnightLightning

Yes, those may be all drawbacks for PHP and I can't wave all of them away, but in choosing a web programming language, here's some of the pros that put PHP ahead of the pack in my book that haven't been mentioned yet:

  • Direct access to GD image manipulation from the source code. ASP could pull in ActiveX components to manipulate/output graphics, but PHP allows native manipulation of image canvasses, and can create image output rather than text/HTML.
  • One programming language usable in CLI/shell scripting and web-based scripting. If you're a new programmer, learning this one language gives you a leg up on both dynamic website creation and shell script automation.
  • Smarty Template engine: Yes, PHP lends itself to combine the display of a page with the processing code, but the same company that designed PHP designed a template system to go with it. Plus having the ability to combine the 'View' with the 'Controller' allows for rapid prototyping/debugging in certain situations.

42
[+1] [2010-04-09 04:02:55] Calvin Haspers

Given all the reasons that it's not, there is one reason we keep going back to using it in almost every solution we provide to our clients.

It's very cost efficient! It's breadth of available programmers, it's ability to work on any OS, it's interoperability with all the major opensource data storage engines and it's ease at which you can go from quickly developed prototype to a full out robust application.


The reason it's a bad language is because every point you list is true of other languages, only they do them better. - meagar
Cost efficient means CHEAP and you get what you pay for. I wonder how much PHP programmers in China make. - kirk.burleson
43