This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here.

More info at http://stackoverflow.com/faq


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!

link
79  
There's no satisfying answer to your question. I can substitute any other language/tool for PHP in your question. – Robert S. Nov 21 '08 at 16:21
61  
it is horrible, but that doesn't matter. totally irrelevant. – Jeff Atwood Nov 22 '08 at 17:26
18  
Every symbol needs a name in the lexer/parser. T_PAAMAYIM_NEKUDOTAYIM refers to the :: symbol. It's a conceit by an Israeli developer from long ago - and it means "double-colon". :-) – staticsan Nov 25 '08 at 0:18
105  
To all people who use the "but it works" argument: One can write programs in brainfuck, one can write websites using c++, one can write GUI apps using assembler,... and guess what, it works! It's one of the most STUPID arguments, sorry. – ivan_ivanovich_ivanoff Apr 29 '09 at 22:01
59  
"There are only two kinds of languages: the ones people complain about and the ones nobody uses" -Bjarne Stroustrup – DShook Oct 12 '09 at 21:53
show 40 more comments
feedback

locked by Bill the Lizard Jun 4 at 13:24

closed as not constructive by Tim Post Apr 30 at 9:36

This question is not a good fit to our Q&A; format. We expect answers to generally involve facts, references, or specific expertise; this question will likely solicit opinion, debate, arguments, polling, or extended discussion.

protected by Matt Ball Mar 4 at 21:32

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned more than 10 reputation on this site.

78 Answers

1 2 3
up vote 559 down vote accepted

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

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

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

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

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

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

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

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

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

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

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

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

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

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

I totally 100% agree with this.

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

*Hmmm, this topic sounds desperately familiar...

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

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

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

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

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

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

link
16  
Nicely said on all counts! – Adam Franco Nov 21 '08 at 19:32
18  
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 Nov 21 '08 at 20:23
5  
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 Nov 22 '08 at 8:27
106  
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 Nov 22 '08 at 8:29
18  
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 Nov 23 '08 at 1:05
show 29 more comments
feedback

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.

link
18  
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 Nov 21 '08 at 16:32
5  
Faster than Ruby, perhaps, but I'm not a fan of Ruby either (I do respect its goals as a language, they're just counter my own). It's slower than Python or Perl, IIRC. – Jason L Nov 21 '08 at 16:36
1  
This is a good answer (and upvoted), but I'd like to point out that 7 out of 10 of my complaints can't be resolved by good coding practices. ;) – Jason L Nov 21 '08 at 16:37
3  
"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 Nov 21 '08 at 17:22
4  
"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 Dec 11 '08 at 20:41
show 6 more comments
feedback

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

link
38  
+1 Spot on: "poor programmers get very defensive about their language". – JesperE Dec 30 '08 at 12:08
12  
@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 Jan 23 '09 at 21:53
7  
It is not simple. You just only stumble across the complexities by accident, usually without noticing. There are other simple and effective scripting languages that lets the general public get things done. PHP is a messy, inconsistent language which lets the general public create problems. – jalf Mar 7 '09 at 11:01
64  
a poor programmer is anyone who needs a language to impose design patterns for them, most of these people hate PHP – Fire Crow Mar 25 '09 at 2:31
21  
+1 for "So perhaps PHP's "strength" is really that no good alternative exists." Awesome point! – Ilari Kajaste Oct 15 '09 at 9:06
show 11 more comments
feedback

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

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

link
3  
Alright, that's an answer I can get behind. The docs are good. But I'm curious; what about the class system is better? I recall it being rather short on features. Functions aren't first-class, IIRC, and you can't inherit from built-in data types, just to name a couple of shortcomings. – Jason L Nov 21 '08 at 16:41
2  
Brian, what Perl's system? – Leonardo Herrera Nov 21 '08 at 20:15
28  
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 Nov 21 '08 at 21:58
17  
I couldn't agree more, PHP's documentation is one of the best things about it, not because of the documentation per se, but because of the stellar, hand picked comments & real world examples of the code. – TravisO Nov 24 '08 at 23:39
6  
I agree with nerdabilly - The documentation is not just poor but in some cases plain wrong: php.net/manual/en/function.date.php you can't call date() multiple times in one function - the date changes at midnight and many of these examples would come up with a wrong date/time combo, and when I posted that observation they deleted my posting! – jdkoftinoff Jul 16 '09 at 23:09
show 6 more comments
feedback

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?

link
17  
What an awesome analogy! – Ilari Kajaste Oct 15 '09 at 9:31
7  
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 Jul 14 '10 at 16:50
15  
I agree. Cars should be banned. :) – Christopher Creutzig Jul 21 '10 at 8:30
4  
@Sean McCleary, 100 times upvote! – topright gamedev Oct 19 '10 at 21:29
3  
@kirk.burleson What's real funny is that there is a very good and non-scary reason for upvoting this answer, it points out the distinction between an irritation by academical disagreement and a flaw of usability by impractical design, something that in my opinion is very important to keep in mind while taking part in this (kind of) discussion(s). (And if you won't buy that, I guess 42 people just had good laughs at the joke.) – Pelle ten Cate Jan 28 at 12:48
show 7 more comments
feedback

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.

link
2  
Sure, here's an example. It's fairly common in object-oriented languages to have a class definition be title-cased (e.g., Thread) and an instance be lower-cased (thread). In expressive languages, function factories follow the same convention (e.g., tostring = ToString(...)). – Jason L Nov 24 '08 at 16:48
4  
Also, regarding the "not giving it a chance", I programmed in PHP for years. Granted, this was several years ago, but I walked into the experience thinking, "Awesome, a cool new web language!" and left that experience vowing to never use it again unless I was starving and only PHP was paying. – Jason L Nov 24 '08 at 16:49
1  
Everyfuckingbody uses dot (.) for namespace "dereferencing". But noooo... they had to choose the lame backslash... Ofcourse you can ignore this but all these small ignorements add up and barf you go.. – Andrei Rinea Dec 17 '08 at 1:09
2  
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 Jan 18 '10 at 1:57
show 3 more comments
feedback

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.

link
6  
Although I am anti-PHP I must salute your objective and clear comment. – Andrei Rinea Dec 17 '08 at 1:27
1  
I'd upvote this... except the vote count is right now at 42... – JavaAndCSharp Jun 3 at 0:10
show 4 more comments
feedback

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.

link
2  
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 Nov 21 '08 at 16:58
4  
I work with PHP (Symfony), Django and Java (Echo2) and, for a basic content driven user facing site Symfony is the easiest. Django is more powerful but time consuming. Java is great for web apps but tricky for the basics. For some things, and despite it's flaws, PHP "just works". – Colonel Sponsz Nov 21 '08 at 17:06
show 5 more comments
feedback

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.

link
4  
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 Dec 17 '08 at 1:30
2  
While I admit that Perl is neither pretty nor "easy", I would hardly call it nonsensical. I thought to myself "Hmm, that sounds interesting, the size of an array in a hash reference. Well, you deference the hash pointer with -> to get to the array (Simple enough, any undergrad should get that), then use it in a scalar context, which is the common way to get the length of an array. Well it must be more complicated after all his complaining..." So I tried it, and guess what: $hashRef->{"MyArray"} yielded "5" just like it was supposed to. Simple? No. Logical? Absolutely. – Jax Jul 25 '09 at 0:12
5  
"So don't blame the gun, blame the guy who pulled the trigger" PHP: the AK47 of web languages. – philistyne Sep 21 '09 at 14:55
1  
People forget that php replaced perl/cgi as the dominant UNIX environment. It wasn't ever competing with JAVA, .NET, ruby, or python. It just had to have an easier syntax than perl – Bryan Waters Nov 12 '09 at 23:49
feedback

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

link
31  
And after they added their code, you now have two problems. ;) – jalf Nov 21 '08 at 19:49
8  
And then a third one comes in and says he/she needs to re-write everything... – Andrei Rinea Dec 17 '08 at 1:05
1  
ya the fourth will advice you, to change the framework at all :) – martani_net Mar 21 '09 at 16:58
2  
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 Jan 21 '10 at 16:24
show 1 more comment
feedback

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.

link
2  
Wow, as if all the people trashing PHP wasn't bad enough, you decide to go after an entire group of programmers. Elitism doesn't serve anybody. Yes, PHP is easy to learn, and doesn't look very pretty. It can also create excellent applications with a decent programmer behind it, like any language. – MattBelanger Nov 22 '08 at 1:55
4  
But that doesn't invalidate his point. If a language's main feature is that it's simplistic at the expense of power and "correctness" (from a design perspective), it's valid to point out that its supporters are going to tend to be "lesser" programmers in terms of knowledge and talent. – Jason L Nov 24 '08 at 16:44
4  
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 Jan 21 '10 at 16:32
1  
PHP "scripters" are definately "lesser" programmers. I've met more than a few who think they know C because they program PHP. What morons. And yes, most web programmers are way below standard. – kirk.burleson Jul 21 '10 at 1:27
show 2 more comments
feedback

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?

link
show 1 more comment
feedback

The huge pile of

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

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

link
1  
I don't think any of those are specific to PHP, though. I can say the same thing about .NET, too. Granted, there aren't as many open source projects, but there are quite a few. As for the jobs aspect, the lack of competitive pay is the reason I changed platforms when .NET came out. – joseph.ferris Nov 23 '08 at 2:55
2  
@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 Mar 1 '09 at 10:33
show 2 more comments
feedback

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

link
7  
"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 Nov 21 '08 at 16:56
4  
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 Nov 21 '08 at 17:01
1  
"such as C#, you spend a lot of time casting your data types for use in various objects." That's not how I program. – Max Lybbert Nov 24 '08 at 23:57
1  
uch as C#, you spend a lot of time casting your data types for use in various objects - wrong – qui Dec 1 '08 at 13:55
1  
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 Sep 18 '09 at 22:22
show 3 more comments
feedback

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.

link
3  
The problem is that PHP does not nail what it was meant to do. It was meant to access a database, and produce HTML. And it sucks at both. Database access typically without parametrized queries, and (x)html in a language which doesn't support Unicode? And where you manually have to escape everything – jalf Nov 22 '08 at 13:08
6  
@Jalf - your database complaint is all about the programmers using the language, and has nothing to do with the language itself. You can write insecure code in any language – MattBelanger Nov 22 '08 at 15:04
2  
The existence of mysql_real_escape_string speaks volumes not only about the security of PHP, but also about the joys of having completely different APIs for accessing different databases. Thank god for PDO. – Kibbee Nov 23 '08 at 0:39
show 4 more comments
feedback

It's free!

Oh wait...

link
6  
... and worth every penny! – Bruce Alderman Nov 21 '08 at 19:36
2  
... not a penny more. – Brad Gilbert Nov 22 '08 at 1:40
4  
Free as in Zend Accelerator. – Andrei Rinea Dec 17 '08 at 1:10
1  
Andrei: APC. Xcache. Eaccelerator. – David Caunt Oct 26 '09 at 23:18
show 1 more comment
feedback

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.

link
1  
"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 Apr 21 '09 at 7:01
show 1 more comment
feedback

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.

link
show 2 more comments
feedback

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.

link
3  
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 Nov 25 '08 at 16:49
2  
+1: More because I agree with the aphorism than the rest of the post... I wish more folks thought in this way. – TokenMacGuy Jul 16 '09 at 22:56
show 1 more comment
feedback

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.

link
show 1 more comment
feedback

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.

link
1  
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 Sep 28 '10 at 18:14
show 1 more comment
feedback

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!

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

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

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

link
show 1 more comment
feedback

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.

link
feedback

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

link
1  
@cfeduke - not necessarily 'designed to' but definitely 'promotes' – Simon_Weaver Jan 31 '09 at 22:00
show 2 more comments
feedback
  1. It's free.
  2. It's easier to maintain than Perl, the older P in LAMP.
link
show 3 more comments
feedback

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

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

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

Web 2.0 clearly shows a trend to PHP.

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

link
show 7 more comments
feedback

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.

link
show 6 more comments
feedback

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

link
show 4 more comments
feedback

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.

link
feedback

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.

link
show 3 more comments
feedback
1 2 3

Not the answer you're looking for? Browse other questions tagged or ask your own question.