views:

26933

answers:

84

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:

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

  • PHP has inconsistent parameter ordering of built-in functions, eg array_map vs. array_filter which is annoying in the simple cases and raises all sorts of unexpected behaviour or worse.

  • 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.

  • 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!

  • 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!

  • 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.

  • 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.

  • 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 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.

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

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!

+8  A: 

It's free!

Oh wait...

Vincent Van Den Berghe
... and worth every penny!
Bruce Alderman
... not a penny more.
Brad Gilbert
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
Andrei: APC. Xcache. Eaccelerator.
David Caunt
A: 

Non-programmer types can use it?

Christopher Mahan
As Jason pointed out, that's not a good thing.
Elie
Exactly. To give an extreme but valid parallel:Q: "Why should we sell guns in the high school cafeterias?"A: "Well, it makes it easier for kids to get guns."
Jason L
Hmmm... Remember when the church didn't want the bible to be translated into English...?
Ben
@Elie and @Jason - Bullshit. Every single programmer was originally a non-programmer. Reducing the barriers to entry is a good thing.
ceejayoz
why should it be easier for a nonprogrammer to use PHP than to use Python? Oh, I forgot, it's a programming language.
Vasil
Jason: if kids can kill enemies why not selling (oh it should give, since php free) to them ? :) if non programmer can use and utilized it .. isn't good ? they can learn how to write good code later.
nightingale2k1
Show me one PHP programmer that is able to write good code.
Willi
@Willi: Define good code.
Christopher Mahan
@Christopher: in college you learn what "good code" is. Granted, there are other ways, but when a nonprogrammer learns PHP as her first language, I doubt she will write programs following accepted standards in other languages later on.
stevenvh
@Willi: I'll define good code for you then: gets the job done, and gets the money into the business. plenty of php code does that. Doesn't follow "Approved Standards"? Many people only care about the money. Academia vs MainStreet.
Christopher Mahan
@Christopher "Good code" is structured, documented, readable and therefore reduces maintenance costs. I have hardly seen any php code out there that satisfies these criterias.
Willi
Jason L
Good style always falls partially on the programmer, and partially on the structure of the language. No language can directly enforce good style, but a language can certainly inhibit good style.
Jason L
Also, this is why I got so annoyed with the inconsistent library/built-in names. Consistent naming patterns are an important, though subtle, aspect of good coding style. Ideally, a programmer in a given language will adopt the same naming style as the standard library, to ensure that all code is consistent in this regard, including library and built-in calls. But if the library and built-in calls are inconsistent, you've literally been barred from adhering to a properly consistent naming style.
Jason L
Christopher Mahan
I'll go a step further and say that true artists will develop their own style (music, painting, writing, etc) by selectively and purposefully ignoring the prescribed style. To follow "best practices" unerringly leads to stagnation. Maybe PHP's success reveals that.
Christopher Mahan
A: 

No can do... it's great, as long as you don't actually use it or support it.

Elie
+18  A: 

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

zaratustra
And after they added their code, you now have two problems. ;)
jalf
And then a third one comes in and says he/she needs to re-write everything...
Andrei Rinea
ya the fourth will advice you, to change the framework at all :)
martani_net
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
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
+9  A: 

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.

Ben
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
+124  A: 

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.

Vinko Vrsalovic
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
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
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
"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
"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
+16  A: 
Mischa Kroon
I think "easy to find jobs using it" is a valid point. We all have to eat. ;)
Jason L
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 wages2. How much cheaper is PHP hosting compared to .NET? 20%?
Andrei Rinea
@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
+37  A: 

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.

Noah Goodrich
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
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
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
+87  A: 

In addition to the above, php's documentation kicks ass. http://www.php.net/rand and you go right to the doc 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.

Brian C. Lane
PHP's documentation is easily the best thing about it.
Chris
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
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
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
TravisO
I agree with nerdabilly - The documentation is not just poor but in some cases plain wrong: http://www.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 When working in PHP, PHP.Net documentation is my first choice. In .Net, MSDN documentation is my _last_ choice.
Cory House
+1  A: 

Probably the same reason people like VB. It looks easy for a newbie to jump into. Then, once you learn a little bit about it, you want to protect the time investment you spent to learn it, which can translate into refusing to learn another language, or flaming people on the internet who disagree with you

rotard
This tells me why people get nutty about it, but doesn't do much to convince me it's a good language. In fact, it reinforces my dislike. ;)
Jason L
The comparison between VB and PHP is a valid comparison, both languages I consider 'entry level' languages that let you get things done and learn about programming. I'm not saying that you cannot do anything useful with them, they just tend to be considered 'easy'. You gotta start somewhere.
Redbeard 0x0A
+16  A: 

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).

TravisO
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
"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
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
"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
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
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
+2  A: 

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.

OIS
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
That should be "some 'php sucks!' jerk"
Chris
"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 http://en.wikipedia.org/wiki/Python_(programming_language)#Standard_library
OIS
@OIS I don't think that's accurate, see http://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
+452  A: 

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 dynamic vs static 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".

Peter Bailey
Nicely said on all counts!
Adam Franco
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
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
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
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
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
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
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
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
"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
@andrei - that sounds more like a personnel problem rather than a technology problem. @Bailey - terrific answer!
nickf
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
you nailed down.
Mohamed
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
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
- Summer Galu (http://xkcd.com/406/)
shoosh
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
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
@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
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
PHP sucks no matter how much you try explain that's not.
killown
@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
there is nothing to discuss, PHP SUCKS.
killown
"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
+101  A: 

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. ;)

jalf
+1 Spot on: "poor programmers get very defensive about their language".
JesperE
@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
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
@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
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
a poor programmer is anyone who needs a language to impose design patterns for them, most of these people hate PHP
Fire Crow
@jalf> Your comments about alternatives are partially untrue. Both ASP.Net (via Mono) and Rails (via mod_rails) can run on Apache.
Paul
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
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
+1 for *"So perhaps PHP's "strength" is really that no good alternative exists."* Awesome point!
Ilari Kajaste
ASP has neither WebForms nor ViewState. Did you mean ASP.NET?
Joe White
"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.
+21  A: 

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.

Richard Levasseur
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.
mabwi
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
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
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
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
+1  A: 

Like so many other things in this world, being the most popular, most widely used, and most readily available does not mean that a product is of the highest quality.

A big part of the lure of PHP is its availability and ubiquitousness.

as I posted in a comment above, my biggest complaint with PHP was its documentation. The organization and quantity was fine, but I found that things were not explained well, in a way that a newbie or non-programmer would understand, and that the examples would only add to the confusion by using shortcuts, trickery, and esoteric functions.

nerdabilly
A: 

I'm in a similar spot, and while there's a lot I don't like about it, I'll probably switch to using PHP as my primary development language because its one of the few that lets me not worry about if its a Widows Server or if its a Linux server etc.

But then again, I use Classic ASP - what do I know? :p

AnonJr
Exactly, what do you know?
kirk.burleson
A Widows Server. Love it.
Christopher Mahan
Snide Windows Server comments on a site using (to great effect) a Windows Server. Love it. - and they've got me looking at .NET again.
AnonJr
+45  A: 

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.

ceejayoz
Could not have put it better myself.
Kevin
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
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
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
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
+3  A: 

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 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.

artificialidiot
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
@cfeduke - not necessarily 'designed to' but definitely 'promotes'
Simon_Weaver
+11  A: 

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.

Ali
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
@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
mabwi
Yeah this answer is defending PHP because its pretty good at being simple IMO, nothing more.
Ali
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
A: 

I am not going to convince you of anything, so let me put it this way...

Microsoft Word is horrible. But, why are there lots of people with a PC running Windows running Microsoft Office using Word?

PHP is horrible. And, there are lots of people with a PC running Linux running Apache using PHP.

Defend Microsoft Word; convince me it isn't horrible. Lots of people use it and it's horrible, but it's usable and lots of people use it.

Mark Stock
Why you say Microsoft Word is horrible?
alexmeia
Perhaps he said it because it is! Anyone can see that ;)
Philip Morton
Have you used MS Office 2007? If not TRY IT!
Thomaschaaf
No, thanks... I'd rather not spend that much money just to see how awful something is.
Dave Sherohman
Isn't Microsoft Word the standard for document editing? Also, a majority of PHP programmers use Windows.
Kevin
This argument is completely nonsensical.
Jason Baker
This whole answer is plain stupid. I'm sorry but I prefer to say it directly rather than lying. What's wrong with MS Word? At least the author of this question said what he thinks is wrong with PHP. You didn't. (regarding MS Word).
Andrei Rinea
@Thomaschaaf : I am using Office 2007 for a year now and I had some difficulties acomodating to the ribbon but now I love it.
Andrei Rinea
don't you people understand what playing devils advocate is ? http://i57.photobucket.com/albums/g212/nicoleavila75/devils_advocate.jpg
Simon_Weaver
really, ms word is horrible, I think you are like my teachers, the are in love with notepad and such tricks lol ;) OMG!!!!!
martani_net
I love PHP and I like this response - upvote for you
Fire Crow
He never use Microsoft Office and just hatred toward microsoft company :)MS OFfice 2007 is great ... windows 7 is great as well ... wow :)
nightingale2k1
+3  A: 

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.

ehassler
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
+74  A: 

Wikipedia, Facebook, Yahoo!, etc.

Nobody cares if you think PHP is horrible. Comparing programming languages is like comparing tools: Convince me hammers aren't horrible! The truth is, you aren't limited to just using one language, use many languages. Choose the ones you think will best accomplish your goals.

Kevin
Wikipedia is a great example. The MediaWiki Code is absolutely horrible (although they try to clean it up), yet the end result is a system that it relatively stable and just works.
Michael Stum
A factory some decades ago created high-quality watches with glow-in-the-dark faces. Great product, fashionable and durable. Also, most of the factory workers got cancer due to the production methods which exposed them to radiation. The quality of the end-product doesn't obviate concern re:tools.
Jason L
An extreme comparison, but it makes the logical point that the end product excuses nothing. Maybe PHP is the best production language for the web. So what? Slavery is the best crop production and factory production method. Does that excuse the valid arguments against slavery?
Jason L
Did you just compare PHP to slavery
Kevin
I like programmers who think what language they use determines how good their software is.
Kevin
It's not an irrational perspective. The language you express yourself in does effect your thinking, down to the lowest levels. I'm not sure if you're bilingual, but even natural human languages have that effect.
Jason L
still it's so academic to put the language over the outcome. and you can't compare php to slavery. php is free, slaves are uhmm...not.
tharkun
I don't think the comparison was to slavery... perhaps it was a comparison to wrongful death? Every php project I've seen has "Important security vulerabilities" every two weeks. I can understand some vulnerabilities are not straightforward but php, as a language, positively fosters poor programming practices and vulnerable coding techniques. There are so many other languages out there that are more efficient, safer AND easier to use.
jdkoftinoff
Reference to one radium watch factory: http://en.wikipedia.org/wiki/Radium_Girls
Ed Griebel
When I wrote this answer two years ago I was a PHP developer. I have since then contracted a serious mental illness from too many paamayim nekudotayim errors and unset variable notices. My company has also gone bankrupt and I am homeless. Thanks a lot, PHP.
Kevin
There is a simple reason why PHP is popular. Most people developing software these days are self-taught programmers and frankly, nearly 80% of them are better off pouring concrete. So what's the best language to pick up and make easy money doing some contract work w/o actually having a degree? PHP! Any 14-year-old who dabbles in server-side scripting knows it. It's 3 times easier to find a PHP dev than Java, .NET and etc. Unfortunately the outcome is piles and piles of shitty unmaintainable code. Yes it is horrible, but its benefits (mainly maintenance costs), outweigh its cons.
Sergey
-1, because tools can be well balanced and handy or not.
topright
A: 

Never understood the attraction of PHP.

FastCGI is available for IIS and Apache and it has some very cool features. Do a Google search for "FastCGI — The Forgotten Treasure" for a detailed description of the context switching and multiplexing benefits of this technology.

You can write an application for it with any language including C, VB and FreeBasic. (.BLOAT have their own 120MB run time module "solutions")

of course you could write a web app with C. the question is why would you want to? string handling is atrocious in C. web programming IS string handling and lots of it. why make your life harder? I could never understand why anyone would write a web app in C.
gnomixa
A: 

I like PHP. It's comfortably similar to C and fairly easy to follow, depending on the way it's combined with HTML. I recently started using it for command line utilities too, and use it on almost all my website projects.

For comparison, last time I saw perl code I got a headache :(

As for "spawning poor programmers", I'd like to refer to the comfortable similarity to C and note that until quite recently I was a Basic nut. Many people told me to stop using Basic, and PHP really helped getting used to the idea of using C, so it can't be that bad ;)

Kawa
+1  A: 

Jason,

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.

Unfortunatelly i can't answer your question, because you're totally right in your post.

IMO the problem is that PHP isn't actually a formal programming language but something like a toolbox for developing html "templates". It was great 10 years ago, but today they are several best choices.

In fact PHP didn't make any futher progress since PHP3 appeared. Ok, ok they have added something similar as o.o. to Php4 and 5 ... but sorry guys this is not actually a Oriented Programming language.

As you i have several reasons to not consider it a formal programing language as Python or Ruby or Put-here-your-prefered-programming-language does.

Gravstar
Why isn't it OO language? Most OO patterns can be implemented in PHP5 just fine, and it made huuuge progress since PHP3. PHP3 was lousy template language. PHP5 is a decent language with lousy legacy templating syntax (which IMHO shouldn't be used).
porneL
+7  A: 

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.

Prajwal Tuladhar
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
+1  A: 

PHP isn't less secure than any other language, and if you build correctly, you can build applications that are just as robust as any other web application framework.

Some people get all wrapped around Comp Sci theory and that makes them dislike PHP. They forget that in theory there is no difference between theory and practice. In practice there is.

The end result is what counts, and when it comes to defending PHP, I only have one word...

Wikipedia

Ryan Smith
Yeah... FORD.One of the most sold cars in North America. Is it the best? Far from it... F O R D = Fix Or Repair DailyA PHP of cars..
Andrei Rinea
+36  A: 

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.

staticsan
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
+11  A: 

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.

Eli
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
+1: More because I agree with the aphorism than the rest of the post... I wish more folks thought in this way.
TokenMacGuy
+1  A: 

Two words, It works!

partoa
That'll convince him.
kirk.burleson
+3  A: 

For me, PHP is certainly not the best thing since sliced bread. However, unlike ASP, it tends to solve my problems.

mike nvck
ASP? Classic ASP? ASP.NET Webforms or ASP.NET MVC? The last one is one of the best solutions available out there. The first is lamer than PHP 3. The second is just ok.
Andrei Rinea
Point taken, I may be just too biased due to my Microsoft grudge and growing up on JS+PHP+MySQL.
mike nvck
+25  A: 

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.

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
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
"So don't blame the gun, blame the guy who pulled the trigger"PHP: the AK47 of web languages.
philistyne
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
A: 

You really need to read Adman Bosworth's talk to iscoc04. or Computer Scientists vs. Developers (in Joel's book Best Software Writing vol 1).

Other people have given a point by point rebuttal, but to take just one of your points -weak typing. Strong typing is taught as the one true way, but weakly typed languages tend to succeed in the market place - C vs Pascal etc. Java and its knock-offs are the only strongly typed languages that have succeeded.

Type checking just isn't that useful in practice, and it gets in the way more often than it actually helps.

Developers like PHP because it's sloppy and forgiving, Computer Scientists hate it for the same reason.

alimack
what is the weak typing and waht is strong typing ... i gets my job done in php without knowing that. is it important ? :)
nightingale2k1
java ? you must be kidding. try Groovy instead. forget about plain java :)
nightingale2k1
Strong typing is when you must declare ahead of use the type of a variable (integer, string, floating point). You don't do this in PHP but are required to in Java. To change the type in a strict environment you need to cast it.
alimack
@nightingale2k1 - Weak typing is what you do in your comments when you don't use capitalization. Let me guess, you don't have a degree and just "picked up" PHP as you went along. :)
kirk.burleson
+2  A: 

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

I heard Rasmus explain this at a conference. In the beginning he simply choose to use the same function names and parameters as the underlying C libraries. If you know the underlying libraries then you know what something probably will be in PHP.

Zoredache
That's a possible explanation for *why* it is as horrible as it is, but it's still horrible.
meagar
+1  A: 
  • yahoo
  • facebook
  • flickr
  • wikipedia
  • wordpress

Good enough for ya?

jakemcgraw
No.Ford, Dodge, Chevy.. Great, ha? Widely spreaded... cheap and low-quality. Just like the sites you mentioned.
Andrei Rinea
andrei, what are the good quality sites? (non php i assume?)
gnomixa
A: 

i like php, using one of the many available mvc frameworks addresses most of issues pertaining to poor programming practices. you can use zend framework or one of my personal favorites the kohana framework written exclusively for php5.

Why do you not use proper capitalization?
kirk.burleson
+9  A: 

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.

lo_fye
"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
+2  A: 

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.

+1  A: 

I'm not at all a trained programmer. I took Java classes and code regularly in AS 2,3 and PHP.

I did, however, program lots of things in Basic 20 years ago so i'm at least somewhat a veteran.

  1. PHP was easy to learn and feel like I did something useful.
  2. PHP has a huge community that helped me grow as a programmer.
  3. After building x number of apps, I no longer cared about "doing something useful" I cared about doing the same useful things "better" and more "elegantly" and PHP gave me enough rope to hang myself or validate my feelings of being a decent programmer.

I don't prefer PHP to anything else as I only have a limited knowledge of other items. But I do like PHP because I now know the difference between a good programmer and a bad programmer and I wouldn't have this experience or knowledge if I wasn't allowed to be a bad programmer first.

jerebear
+15  A: 

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
+1  A: 

PHP has many drawbacks, if you think this is a problem, don't use it.

I was aware of these and used it anyway for some projects. In practice, problems don't actually prevent the writing of good code, they simply make it very slightly harder. And there are a lot of workarounds.

I don't get your issue about function references; PHP does not support anonymous functions therefore function references are irrelevant, just call functions by name which a callback can do (No, really, create_function just creates a named function with a dynamic name. Last time I checked there was no way to deallocate these).

PHP is, by and large, so stupid that it forces you to think about how things are actually going to be done rather than relying on some underlying magic (e.g. all the voodoo from ASPNET) to "just work", e.g. sessions aren't automatic and implicitly available, you need to start them.

This can be a good thing as it means that all of the things you want to do, you have to actually do.

MarkR
+1  A: 

PHP's one of the biggest problems are novices who can't take the time to do validation etc and this leads to security problems which causes bad imago 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 apps 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 it's 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 what you need just aren't there.

I've also seen that PHP is fading but frameworks like Symphony and Zend Framework may be these future saviours of PHP.

raspi
+2  A: 

This is what is said in the book XSS attacks (syngress) by : Jeremiah Grossman -
Robert “RSnake” Hansen - Petko “pdp” D. Petkov - Anton Rager

Another nasty thing that can be performed by CSRF is Hypertext Preprocessor (PHP) include attacks. PHP is a programming language that has increased in popularity over the last several years. Still, while it is an extremely useful and widely used programming language, it also tends to be adopted by people who have little or no knowledge of security

so if php is that simple, it would be a big problem since everyone will just mess up with things on the wild!

martani_net
A: 

The above questions are exactly why I like it. Every single reason!

Every point in your post is about how PHP will not organize your code for you.

I'm proactive, and I need a level of organization no code will give me out of the box. I'd rather a language that stays out of my way and let's me enforce good program design with actual design, like pencil and paper planning design.

And as for teaching beginners bad habbits. you can't prevent bad habits from the language level nor can you implement good design from the language level.

Fire Crow
A: 

PHP doesn't need defending; why should I? ;)

Babiker
+4  A: 

1) It's Free. 2) It's easier to maintain then PERL

Bryan Waters
+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
+2  A: 

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 and a ostrich 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.

Robert DeBoer
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
A: 

in my opinion.

i love it because the code is updated very frequently by the general public rather than employees of a company (who can care less).

one language i really hate is asp,asp.net etc.. anything made by microsoft is garbage. the code that visual studio generates is a mess of blob. and since it forcefully operates on a windows makes it even more insecure and crappy.

php is universal. it can run from a window,linux,osx

wherease asp,asp.net only run on windows.

SarmenHB
"who can care less"? see http://forums.applenova.com/images/ammo/i-could-care-less.jpg
stevenvh
A: 

I'm surprised that the thing which infuriates me the most about PHP doesn't seem to be mentioned in the question or any of the answers: its scoping model.

It's infuriating to me that this doesn't work:

function outer() {
    $foo = 'bar';
    inner();
}
function inner() {
    doSomethingWith($foo);
}

$foo has not been garbage-collected—for chrissake it's still available after inner(), within outer(). It's technically still available within inner() if calling inner() triggers an error! Why should it need to be explicitly passed as an argument, or worse part of the global scope, to be accessible within inner()?

eyelidlessness
You think that's a problem with PHP?! There's a truckload of trouble waiting for you if you'd work in a language that *would* support it -- information hiding would be gone, creating a huge tangled mess of interdependencies, e.g. library code could (unknowingly) change the way your methods work. Good luck debugging that.By putting variables in arguments, at least you know that the function only works on globals and those arguments (and only if passed by reference).
Lennaert
Lennaert,Most of my work is with a language that does allow it. What you're describing as a danger—which it is, in an environment where you unwittingly use outside code that hasn't been reviewed—is also a powerful tool in the right hands, sometimes described as "monkey coding". ECMAScript (Javascript, Actionscript) supports the scoping model I described, and particularly when combined with anonymous functions/closures, it provides a powerful environment for highly dynamic, flexible code. There are plenty of valid use cases, in which code could be simplified quite a lot if it were available.
eyelidlessness
This has to be the most stupid answer I've read on SO. Let's just make all variables global and go back to "line number" BASIC. Passing arguments is too much trouble...
kirk.burleson
@kirk, you must not read much SO. Anyway, what does nested scopes have to do with global variables? Did you read my previous comment specifying a perfectly capable modern language which implements nested scopes? Or do you think ECMAScript is like BASIC and a nightmare of global-scope conflicts by design?
eyelidlessness
@eyelidlessness, nice trolling.
shamittomar
@shamittomar, I promise I am not trolling. It's my genuine opinion that nested scope is a good idea, and I provided an example of a good implementation of it. How is that trolling?
eyelidlessness
@eyelid That is a terrible idea. There is a reason that virtually no C-syntax language allows this.
meagar
@meagar, I'm still waiting for anyone to explain *what* is terrible about it. Nested scope works *great* in ECMAScript, what are the horrors I'm just not seeing?
eyelidlessness
@eyelid Every single time you use a variable, you'd have to worry about clobbering things in the parent scope. Every single function would have to start decorating its variables with unique prefixes. This is an astonishingly bad idea.
meagar
@meagar, this is why languages with nested scope differentiate variable *declaration* from variable *assignment*. ECMAScript, not being strictly typed, has one such prefix: `var`. Other languages will require more verbose prefixes *anyway*. Explicitly declaring a variable is not only more clear to a parser, it's more clear to a reader. I don't see that as a bad thing.
eyelidlessness
@eyelid PHP doesn't have variable declaration, so nested scope is, as has been said *repeatedly*, a *very bad idea*. You can continue to gripe about PHP not supporting features which are completely inappropriate and anti-thematic, but I don't really see the point.
meagar
@meagar, you're begging the question. Twice in one sentence, which is impressive. PHP can't safely implement nested scope without variable declaration; but PHP's lack of variable declaration is already a liability, and I don't think it serves as a positive reason to limit the functionality of scope in the language. The language already has variable declaration in certain contexts (member properties, not strictly enforced; static and non-public properties, strictly enforced), and that should be extended to the rest of the language and strictly enforced, because it will improve PHP applications.
eyelidlessness
@meagar, I have only continued to gripe because I keep receiving responses to this answer that offer (with little exception) no practical reasoning that nested scope is a "bad idea". Believe me, I don't lose sleep over PHP's scope system. But I also don't like leaving misinformation unaddressed under my "name".
eyelidlessness
+1  A: 
nightingale2k1
Interesting how PHP seems to be searched for less and less. But nothing else is rising to take its place...
DisgruntledGoat
+4  A: 

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.

capfu
+3  A: 

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

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

Question Mark
What about the Java API?
middus
A: 

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.

TokenMacGuy
+1  A: 

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.
MidnightLightning
+1  A: 

It's not so much that the language is terrible, but that it has a tendency to attract those people who want to learn language "X" in 24 hours. What happens then is that you have people who (mostly) read a (intro) book on PHP programming and think they've completely mastered all the ins and outs of the language. Consequently, I think you have more of a glut of bad PHP programmers than anything else.

Anjisan
A: 

I like PHP because it isn't ASP.

Paxinum
A: 

PHP is what I write in most. And it is shit, you are right :)

But, it's getting better. And there are many reasons why people would want to use it. Especially those learning a language for the first time. :)

Spot
A: 

In Perl, it's very easy to get a size of an array stored in a hash reference:

my %h = ('easy'=>[1,2,4,5]);
$size = @{$h{easy}};   # gives the size...
What question are you answering?
kirk.burleson
A: 

Simply I'd say that you don't like it and if you never liked it, we won't be able to convince you .......... all of PHP developers around the world can't be wrong ! aren't we ?

tawfekov
C'mon, read what you wrote. Is this your best argument for PHP? You're not helping matters...
kirk.burleson
That's a popularity over quality argument: if it's popular it has to be good. Plenty of counter-examples I think. Just look around you.
stevenvh
+1  A: 

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.

gargantaun
A: 

I come from a python background and I found PHP really inconsistent, totally agreeing with you. Anyway, I think that it's widespread just because it's a standard de facto.

pygabriel
+35  A: 

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 fulfil 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 nonsensicle 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 refuelling)
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?

Gustavo Carreno
What an awesome analogy!
Ilari Kajaste
don't have to be so harsh, PHP is just a humble language
pop850
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
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
@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
@Sean McCleary, 100 times upvote!
topright
A: 

I wouldn't say it's horrible. Is PHP perfect? No. But is any language perfect?

The reason it isn't horrible: ease of use, availability and libraries make it a good language for any programmer to start with. This is probably the reason why many programs are coded with it.

It's also easy to bang out a site and scale. Someone mentioned caching earlier stating that this was a reason why it was a poor language. But again, can you scale any site efficiently and cost effectively without caching? No.

In regards to security, PHP is no different than any other language. I think all web languages have security issues when not implemented correctly.

dw
A: 

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 devteam 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 lets 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, Yui, Zend, Symfony (i leave CodeIgniter out because its supporting PHP4 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 structure are the real bottlenecks for speed.

RJD22
A: 

PHP IS A GREEN LANGUAGE

Would you be content if you had to pay to type in English? With most other programming languages, developers have to pay for client licenses to use and produce. Conversely, PHP is Open Source, so a developer does not pay.

<?
// implied amount for $developers and $cost
$corporations = $developers * $cost;
$openware = $developers * 0;
echo ($coporations > $openware);
?>

In the above example, I have shown in PHP, it is quite true that the money developers pay to corporations compared to what they pay to Open Source projects to going to be greater. A variety of moral issues could be derived from this. For me, personally, I am a creator. I am an artist. Thus, this is a point to ponder.

Of course one could argue an artist has to pay for the materials to do one's work... or not. This is a personal choice. This could also be a requirement.

So for me, personally, when I can - I choose the green option.

True, PHP may be a product with design flaws, bugs, and/or issues to work out. Weigh in all the factors of its shortcomings, its capabilities, and everything else. Then compare that to what is found in designed, or sold development software; it does about as much and it gets the job done.

---edit below due to downvotes LOL---

The real reasons why I LOVE PHP.

  1. PHP lets you bend the rules.. or make new ones.
  2. Insertion of code in HTML anywhere.
  3. Super-fast installation using LAMP/WAMP.
  4. Ability to access and manipulate $_SERVER variables.
  5. Can be used to generate ANY type of file.
  6. Can be used as a web page script or an app.
  7. There is a function/library for just about everything imaginable.
  8. Thousands of APIs for use with thousands of web services.
  9. Error reporting makes it easy to debug and trace code.
  10. Built-in support for almost every kind of database.
  11. Built-in support for almost every kind of image type.
  12. When there is no built-in support, see #7 and #8.
  13. Project files are managed in text and do not need to be compiled into executables.
  14. Full object-oriented language ability.
  15. Can help you get 100/100 on a google page-speed rank.
  16. Can mold to your own programming style.
  17. It can be the language you want it to be with the right classes/functions.
  18. Quirks in the language eventually get depreciated.
  19. Full reg_ex support, and easier to use than PERL. (for me anyhow)
  20. It has enough nuances to keep me learning every day.
  21. There is not much I can think of that is cannot do. (w/ .js and .css of course)
  22. It can handle a database of 1,000,000 records on my laptop and not crash.
  23. Scripts written with it are only as bad as the programmer who wrote it.
  24. The acronym of PHP is self-recursion. which is cool
  25. I find less wrong with PHP than with javascript, which has no alternatives.
  26. The syntax is easy to understand after using it for some time.

I may list more with a later edit...

Talvi Watia
Most major programming languages are open source so I do not know how PHP being open source is a defense for the language its self.
Sean McCleary
pay to type in English? what?
Tom
"Free" has nothing to do with "being green", and you can develop and redistribute software in virtually any language for free. Your answer is pretty much nonsense.
meagar
um... have you seen what most companies charge for compilers, when *not free*?? `http://software.intel.com/en-us/articles/intel-academic-developer-program/` perhaps this is getting downvoted, because it has been forgotten how expensive this really is if your company isn't buying your software for you...???
Talvi Watia
@meager I always thought of DIY as "green". (i.e. opensource)
Talvi Watia
Please, keep programming PHP. You fit in very well...
kirk.burleson
@kirk I plan to. ;)
Talvi Watia
A: 

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, Joomla, Wordpress, 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.

rpSetzer
A: 

This question reminded me of a talk during the Erlang User Conference 2009, where someone was explaining the advantages of using PHP and Erlang mixed together.

http://www.erlang-factory.com/upload/presentations/117/Todd-Lipcon-ErlangFactoryLondon2009-BuildingMulti-LanguageWebArchitecturesusingErlangandThrift.pdf

See slides 7 and 8.

I've almost felt down when I saw slide 7.

Roberto Aloi
+1  A: 

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.

Calvin Haspers
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
A: 

I like PHP! Fast, simple, C-like (sorta). I have so many resources and toolkits at my disposal.

So how does it 'promote poor programming.' What? Was there a sign I didn't see? Everyone starts programming poorly. Should the language be so strict as to force the programmer into submission? I can write bad code in many languages! It's up to the coder to train and discipline himself, not the language. I come from a background of C and Assembly programming. I can write nicely in any of these languages, because I keep training myself, and I keep practicing, and I know my life will be easier if I code cleanly.

Yes, it's a life choice!

And let's be honest, web programming is a huge, sloppy mess. I use 4 different languages for a web page - PHP, SQL, JavaScript, and HTML. PHP generates HTML, JavaScript, and SQL - or only HTML; or not. There is a server side (PHP and MySQL) to consider, security within the forms, the server itself, the SQL script, and a client side (HTML/JavaScript). Programming for the web is no small feat, and the language should not be under the same scrutiny as the posh desktop C++ or Java, where you can enforce coding zealotry with the compiler!

Recursive performance? Why the hell would I use recursion unless I had to? I have programmed recursion in i8086 assembly, and in Pascal, but I have never had an occasion to use recursion outside of school! What are you thinking?

Bottom line: I like it, I use it, and that's it. Fast, easy, free, plenty of free code, plenty of free advice, and plenty of books to choose from. I can design, code neatly, and document via comments (again, free!).

I don't have those problems with the language. I think I should also learn Perl. And Ruby. I don't like C# or VB, but if you do, that's okay.

Get it?

+2  A: 

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).

Ben Dauphinee
+2  A: 

The following is valid code. It's either a horrible abomination or a new type of meta programming...

<?php
$foo = "md5";
$bar = "foo";

echo $$bar("Hi there");
echo "\n";
wmil
It's either enough rope for a noose or enough for a lasso. Which is up to you.
George Marian
It seems like you could do something similar with `bash` scripting...
Benjamin Oakes
... And I used variable variables when I started coding in PHP (I was learning. I got better). It really seems like the dark side of the code beckons the newb.
Adriano Varoli Piazza
There's nothing wrong with variable variables, many scripting languages allow you to do something similar. It's knowing when and how to use them safely that's the trick.
meagar
I was referring to the fact that I was a total newb, and saw variable variables as the best solution to my problem.
Adriano Varoli Piazza
A: 

Bottom line. If it weren't for PHP a lot of developers wouldn't have jobs right now. PHP pays bills. It didn't say it would change the world & it didn't say that you need to use it. Period. You can code bad in any language. If you desire to code well because you value your work, then by all means code to the best of your abilities.

demet8
Bottom line - If the industry weren't drowning in people who can turn out hackish, awful, but technically functional PHP, those of us writing actually *good* software would command higher wages :p
meagar
+1  A: 

For me its php.net'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.

Sane
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
+2  A: 

Language wars are idiotic. This question can't be answered, unless you just like to be swayed by popular opinion or the most shrewd linguist. Failure to learn any language only means you can't communicate in that language. Any loss for choosing not to learn any language is personal. Opportunities will be missed and group association will be further limited, but their importance is subjective.

I'm sure you could rig Brainfuck to be an efficient disk management tool. I'm sure you could design a robotic surgical tool in javascript. Though each language is more or less intended to be specialized (as any human language is more or less adapted to the current, localized environment), most overlap in capability. In fact, I dare say PHP has a mix between several popular scripting or compiled languages. Hell, they even have features of BASIC in there (re: goto), if that's your thing.

If any language doesn't appeal to you, even after reading the manual for deeper insight into it's hidden or unintended capabilities, and even after looking at market share if choice involves a career path, simply move on. Here's a list of the more wellknown programming languages. I'm sure most require just a simple parser or compiler app, and a dictionary/manual handy.

Short answer: if PHP doesn't appeal to you, simply move on to try the next. Or, open a support case with the language's primary dev team to ask them to implement features of other languages you favor.

But with that said, I think more important questions would be financially motivated: "1) Is it worth becoming certified; 2) Is it worth being stuck on a corporate dev team if you hate the language". But you didn't ask that.

Edit: For added complexity about how PHP or any other language stacks up against any other by versatility, see this [arguably incomplete and nauseating] "by catagory" wiki page.

bob-the-destroyer
A: 

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.

Maybe this is because mine weren't complicated enough, but I have used recursion in PHP a few times and never noticed a problem.

John Isaacks
+3  A: 

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.

Aaron
+5  A: 

This remind me of Galileo saying : You know what guys? Maybe I'm just drunk, but what if the Earth was actually rotating around the Sun? Its 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.

BigPat
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."
Chetan sharma
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
+1  A: 

PHP was the first language that I used at all seriously. I agree, there are better languages out there for experienced programmers, but I don't regret learning on it. It's an incredibly simple language that makes it extremely easy to write more-or-less working code even if you know nothing about design. The quality of the documentation is something I would kill for in every other language I used. I managed to write programs that did useful things without even understanding what a class was. I basically just used PHP's insanely powerful associative arrays to structure all my data.

The bottom line is that the value of PHP is that it makes it very easy to get off the ground and just Make Something Work (TM). The same can be said about a few other languages, like Visual Basic. These languages seem "horrible" to more hardcore programmers because they're not designed for hardcore programmers.

dsimcha
A: 

PHP was the first language that I used at all seriously. I agree, there are better languages out there for experienced/hardcore programmers, but I don't regret learning on PHP. It's an incredibly simple language that makes it extremely easy to write more-or-less working code even if you know nothing about design. The quality of the documentation is something I would kill for in every other language I used. I managed to write programs that did useful things without even understanding what a class was. I basically just used PHP's insanely powerful associative arrays to structure all my data.

The bottom line is that the value of PHP is that it makes it very easy to get off the ground and just Make Something Work (TM). The same can be said about a few other languages, like Visual Basic. These languages seem "horrible" to more hardcore programmers because they're not designed for hardcore programmers.

dsimcha
You're saying PHP enables you to turn out bad software very quickly and with no training. This is hardly a point in PHP's favor.
meagar
@meager: No, I'm saying it allows you to turn out **good enough** software very quickly and with no training. Some things don't need to be elegant or efficient. They just need to work, but they need to work quickly and even in the hands of non-gurus. This is where PHP excels.
dsimcha
@meager which is better, overly-complex languages that result in **experienced programmers** creating poor software, or easier languages that result in **poor programmers** creating poor software and **experienced programmers** creating awesome software?
Talvi Watia
+5  A: 

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.

methodin
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
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
+1  A: 

There is no horrible language, there are horrible programmers

Mike
Horrible languages exist and PHP is definitely one of them.
Willi
Language design idea: Function calls are the given name of a function, in reverse, with the arguments following in a bulleted list. Each function call will execute the given function 95% of the time, and execute a different, randomly-selected function 5% of the time.Would this be a horrible language? Yes.(Potentially amusing, but horrible.)If a horrible language can be created, it follows that your answer is incorrect.
Jason L
+2  A: 

I agree with most of your points; PHP as a whole is a mess! What I don't agree on is your view on the case insensitive functions.

"Case insensitivity introduces much ambiguity."  

Not as such: only if the language isn't consistent in this. Case sensitive variables combined with case insensitive functions are a sick idea.
However, I've worked for some time with the totally and completely case insensitive Delphi and I've never had a feeling of ambiguity. So I write FooBar which was fooBar on the previous line. Big deal. It's just like this other case insensitive language, English: you just know they mean the same thing. IMO there's much more ambiguity if you (in case sensitive languages) define two different variables fooBar and FOOBAR. Now that's asking for trouble!
Bottom line: the case insensitive functions in PHP are crazy, but not just because they're case insensitive.

stevenvh
`Capitalization is the difference between "I had to help my uncle Jack off a horse.." and "I had to help my uncle jack off a horse.."` - (found it on bash.org but may have originated somewhere else). Inconsistent capitalization when the language allows it is as bad as having two different variables just differ by case.
delnan
OK, English doesn't seem to be case insensitive :-). OTOH, I don't agree with your comparison: in the former case no harm is done, while in the latter the system reports errors or, worse, behaves erroneously. I see Delphi programs where the programmer writes `WHILE` and others where another programmer writes `while`. If this confuses you you definitely need to learn to focus.
stevenvh
This issue ultimately extends from a root question: is a programming language a form of mathematical notation, a natural language, or something new? I lean toward mathematical notation, which is why I prefer case sensitivity. However, the debate will likely never be settled.
Jason L
Also, you're right. Case insensitivity isn't an issue as long as it's universal. The case insensitivity of most SQL dialects never creates problems for me. However, even in those cases, I tend to write in a case-sensitive manner out of habit.
Jason L
Actually, on further reflection, I take it back. Case sensitivity is important because it enforces consistency in coding style. Why does it matter? The human brain iconifies based on word shape; its a neurological short-cut. People with dyslexia struggle to read because this short-cut is effectively broken for them.
Jason L
So the problem with allowing "If", "IF", and "if" is that while they're identical in spelling, and logically they're the same word, to our brain those are three distinct words which happen to mean the same thing. Code is complex enough, and hard enough to read efficiently, without forcing our brain's background threads to do additional work. ;)
Jason L
Is it a huge hurdle? Of course not, but we have style guidelines for code for the same reason we have them for natural languages. Code is best when it's clear. YOU CAN TELL WHEN I END A SENTENCE THROUGH PUNCTUATION ALONE, BUT THE PROPER USE OF CAPITAL AND lower-case letters still provides valuable visual guidance that your bran uses to more EFFECTIVELY ABSORB INFORMATION.
Jason L
+1  A: 

I don't like PHP, its ugly syntax, its ugly OOP model. It has many conceptual issues, for example:

{ $x = 3; } // variable $x is defined inside inner scope!
echo $x; // outputs 3 - variable is seen in the outer scope!

Another one:

$x = 3;
function bar() { echo $x; } // $x is undefined inside bar's scope

But I've worked as PHP programmer for 7 years and I've come up with my own style of designing and coding PHP programs. By strictly following this style, inside my own "frame", subset of PHP, I wrote secure and well-organized programs.

Now I am C++ programmer. This language is die-hard as hell, but I'm happy.

topright
I also hate the scope thing. I do remember how well it works and C/C++ but fails to work in php :(
AntonioCS
I don't understand why paradigms from another language are used to evaluate how things should be done in PHP. The very same example can be used against JavaScript (I mean literally the same - when you DO NOT have scope btw any curly braces, but have function/object/namespace scope). So, while PHP has a lot of deficiencies, this particular example is shooting the wrong target imo.
Victor Farazdagi
Perhaps there are good and bad paradigms.
topright