20

PHP is not a bad language (or at least not as bad as some may suggest). I had teachers that didn't even know PHP was object oriented until I told them. I've had clients that immediately distrust us when we say we are PHP developers and question us for not using chic languages and frameworks such as Django or RoR, or "enterprise and solid" languages such as Java and ASP.NET.

Facebook is built on PHP. There are plenty of solid projects that power the web like Joomla and Drupal that are used in the enterprise and governments. There are frameworks and libraries that have some of the best architectures I've seen across all languages (Symfony 2, Doctrine). PHP has the best documentation I've seen and a big community of professionals.

PHP has advanced OO features such as reflection, interfaces, let alone that PHP now supports horizontal reuse natively and cleanly through traits.

There are bad programmers and script kiddies that give PHP a bad reputation, but power the PHP community at the same time, and because it is so easy to get stuff done PHP you can often do things the wrong way, granted, but why blame the language?.

Now, to boil this down to an actual answerable question: what would be a good and solid and short and sweet argument to avoid being frowned upon and stop prejudice in one fell swoop and defend your honor when you say you are a PHP developer?.

(free cookie with teh whipped cream to those with empirical evidence of convincing someone —client or other— on the spot)

P.S.: We use Symfony, and the code ends being beautiful and maintainable

P.P.S.: Facebook is written in PHP, compiled to C++ via HipHop and deployed on Hadoop. Here: http://arstechnica.com/business/2012/04/exclusive-a-behind-the-scenes-look-at-facebook-release-engineering/1/

dukeofgaming
  • 13,943
  • 6
  • 50
  • 77
  • 9
    For starters, flag all snarky anti-PHP comments on Programmers. There's at least one PHP developer amongst the moderators who really loves to delete those... – yannis Mar 17 '12 at 04:19
  • 24
    **Write good PHP code** – Charles Sprayberry Mar 17 '12 at 04:36
  • @CharlesSprayberry Well, I already kinda do... now I just need to convince the rest of the bad PHP coders – dukeofgaming Mar 17 '12 at 04:40
  • 2
    I doubt you can, really. Marketeers figured out a long time ago that once a product has a poor reputation, just about all you can do is abandon it and start over with something else -- even (or maybe "especially") if you leave the "guts" alone, you need to change the name. – Jerry Coffin Mar 17 '12 at 07:00
  • 43
    Just a note, I really **HATE** when PHP people bring the "FB is build on PHP" argument in. That's bs, it's built on massive distributed systems like Hadoop and the parts that really get stuff done are in C. PHP is used for templating and the UI, that's hardly enough to say "FB is built on PHP"... – TC1 Mar 17 '12 at 08:23
  • @TC1 - you can say that for 99% projects out there. I can't name 1 project I've done without various systems, each built with something else. Memcached, MySQL, ZeroMQ, Greylog, you name it. Any large website or application serving many users is distributed across different systems in a certain way. – N.B. Mar 17 '12 at 09:47
  • 10
    @N.B. Yes, but in this case, IMHO saying that "FB is built on PHP" is like saying that StackOverflow is built on CSS and JavaScript, 'cause it has some nice UI touches here and there... – TC1 Mar 17 '12 at 12:20
  • 4
    @TC1 - it's not really the same analogy. I don't know for sure what's Facebook built upon exactly, but I'll concede to the argument that you presented - it's annoying seeing people mention Facebook in PHP's "defence". The problem with Facebook is the data - storage and maintenance of the data. That's something PHP has nothing to do with. Analysing, moving and maintaining that amount of data **is** the challenge. I'd rather hear people saying Wikipedia is built on top of PHP, because it started off as something structured (and it's not something trendy, flashy and useless as Facebook). – N.B. Mar 17 '12 at 12:26
  • 13
    I would not hire you because I do not want to maintain PHP code. PHP is gaining features just like Perl and JavaScript and other rushed languages, but its very core has been designed in a hurry and one cannot change that. Perhaps you should consider learning some Django and RoR and Grails and thus be language-agnostic. – Job Mar 17 '12 at 17:06
  • 5
    The fact that Facebook is built on PHP is irrelevant. One good example does not a language make. And secondly, you have no evidence whatsoever that Facebook's development costs were not higher than by using any other language, so it's not even a good example, it's a random, irrelevant, fact. Oh, and the fact that they've been desperately trying to find an affordable solution to moving away from PHP doesn't really support your argument, either. – DeadMG Mar 18 '12 at 01:23
  • Thanks to all, it was good reading diverse opinions and although I'm sad the question was closed, I think there were a lot of constructive answers and comments that help clear the picture. I knew the question would instill drama but wen't on with it because I really think its an important question to ask. Won't ever use the FB argument again. – dukeofgaming Mar 18 '12 at 13:51
  • 4
    The problem is that PHP **is** horrible language. See: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ – vartec Oct 09 '12 at 12:02
  • related: http://programmers.stackexchange.com/questions/62070/what-attributes-of-php-make-it-insecure http://programmers.stackexchange.com/questions/89951/why-do-ruby-and-python-seem-to-have-more-community-contribution-than-php http://programmers.stackexchange.com/questions/63538/my-university-doesnt-provide-php-courses-because-it-is-an-easy-programming-la – vartec Oct 09 '12 at 12:15
  • PHP is not enjoyable. – Tulains Córdova Dec 19 '12 at 20:25
  • @user1598390 Try Symfony2 and Doctrine and you will discover it is – dukeofgaming Dec 19 '12 at 20:32
  • I'm nearly finished with my Master's Degree in Software Engineering, and, I suggest the questioner to listen to what others said. PHP is a bad language. Programmers in PHP are usually paid less and their code is a shade of grey on the scale of badness. There is no good. :) When you apply all software engineering principles to PHP and master ZF2/Symf2, PHP gets more expensive to write than Java EE. Finding anyone capable at that level is much harder than finding Java EE. Maintaining that well is even harder. Extremely few qualified people (i.e. Software Engineering postgrads) spend time on PHP! –  Dec 21 '12 at 12:48
  • 1
    @user42242 Do you have links for the data? – johnny Oct 21 '13 at 03:06
  • @TC1 At the time you wrote that comment FB had over 6 millions LOC in PHP. – oxygen Feb 12 '15 at 10:58
  • php function haystack or needle first ? PHP8 is out, but this has not been fixed yet :D – Rambarun Komaljeet Dec 11 '20 at 06:39

7 Answers7

41

The only answer I have is this: everything sucks.

You can find tons of arguments against OOP being any good (a quick search will reveal them) versus functional or procedural programming. You seem to indicate that PHP's OO support defends it.

Google blank sucks and you will find results for anything. Python sucks. Ruby sucks. Rails sucks. PHP sucks. Java sucks.

You want to know what really sucks? Programmers. Programmers suck. Any good developer should be able to create an amazing application, front end and back end, regardless of the language -- even if they were not familiar with the language! (That is to say, a good programmer should be able to learn and work with any language effectively).

Also note that the success of an application has nothing to do with its code. I've heard that Facebook code is awful, but by God is it effective. Same is probably true of Wikimedia (Wikipedia is built on PHP and is also an extremely popular website). What really matters is results!

PHP is the language that I am personally most familiar with. I will defend it to the death. I have worked with PHP frameworks, straight up PHP code, and PHP, python, and ruby (and even Java) all for web development. I can't say that one is particularly better than the other. What matters more is the developers and the algorithms. I have seen amazingly good and completely awful code in many languages (especially PHP since I have so much exposure).


Now for your question: it depends on who you're dealing with

Businessmen

They care mostly about results and cost-effectiveness. The fact that the very successful Facebook, Wikipedia, and Wordpress use PHP should be more than enough to convince them that it's an effective language for building successful applications.

Programmers

Let your code speak for itself. If a developer says that PHP is inferior in some way, show them some PHP code that you believe to be effective. The proof of the pudding is in the eating.

Explosion Pills
  • 1,929
  • 16
  • 22
  • 8
    "Any good developer should be able to create an amazing application, front end and back end, regardless of the language" - repeat that after you've tried it in Malbolge. – Michael Borgwardt Mar 17 '12 at 07:44
  • 5
    I don't think a good programmer can write good code in language he doesn't know. Decent, maybe, but not good. That's because writing good code in any language requires good knowledge of libraries and the language itself. – svick Mar 17 '12 at 14:58
  • 4
    I disagree; a good developer should be able to familiarize themselves with the necessary knowledge to write good applications. Good knowledge of libraries and syntax is important, but that is something a good developer can pick up easily. What is much harder is algorithms and concepts (and probably patience)..even if the language is Malbolge. Or maybe I'm thinking of a *great* developer. – Explosion Pills Mar 17 '12 at 15:29
  • 7
    `success of an application has nothing to do with its code` <-- True. But when people are saying that "PHP is a bad language", they don't mean "applications written in PHP are bad", rather, they mean "applications written in PHP are often not fun to work on due to code spaghetti". There are great applications written in PHP, to be sure. But I don't think this answer addresses what programmers mean when they call PHP "bad". – Billy ONeal Mar 17 '12 at 15:51
  • 2
    @BillyONeal What is your metric for whether a language is "good" or "bad?" Applications are everything .. nobody cares about *code*. Linus Torvalds went on a rant about how terrible C++ is -- you can say that anything is bad because some programmers write bad code in it. – Explosion Pills Mar 17 '12 at 15:59
  • @Tandu: I don't think anybody is calling PHP bad due to bad applications. Nor was Linus calling C++ bad due to bad applications, he was calling it bad because it's easy to generate spaghetti there. (Which was exactly my assertion in the comment) – Billy ONeal Mar 17 '12 at 16:01
  • @BillyONeal so your metric is the ability to easily generate spaghetti code? I'm not sure that you'd be able to prove you can do that in C++ or PHP more than in any other modern language. – Explosion Pills Mar 17 '12 at 16:04
  • 1
    @tandu: Not "easy to generate spaghetti", but "hard to generate non-spaghetti and/or default behavior is to generate spaghetti". After all, PHP's "default behavior" is to dump implementation details straight into the presentation layer (HTML). – Billy ONeal Mar 17 '12 at 16:16
  • It's difficult to come up with a fair metric for “bad language” so I'd expect any answer to have to be tailored carefullly, but issues like “inconsistency”, “features that easily lead to abuse” and “history of apps with problems” would be the ones _I'd_ probably focus on addressing. Were I even vaguely interested in defending PHP at all, that is… – Donal Fellows Mar 17 '12 at 17:25
  • 1
    *"results and cost-effectiveness"* Fact that Instagram only needs 13 workers in total vs 4000 in FB clearly shows how PHP compares do modern alternatives. – vartec Oct 09 '12 at 12:07
  • 1
    @vartec you think that Facebook and Instagram are comparable in their domain? Not to mention that's not 4000 *developers* working on the PHP side of the website, that's 4000 employees for a huge company that does all kinds of things. – Explosion Pills Oct 10 '12 at 03:39
  • @ExplosionPills: at Instagram it was 13 people **total**; Yes, Instagram has only one functionality, but still, that's a 5 billion photos having only 2 full-time backend engineers (5 engineers in total, including frontend and mobile clients). Would that be possible with PHP? No frikin' way. – vartec Oct 10 '12 at 08:01
  • @vartec yes way; Facebook has *way* more photos than that. – Explosion Pills Oct 10 '12 at 13:20
  • @ExplosionPills: ROTFL. http://www.niallkennedy.com/blog/2009/04/facebook-haystack.html as one would expect, not a line of PHP code there.. – vartec Oct 10 '12 at 13:31
  • @vartec you're only hurting your point; you've just admitted that however many developers worked on Facebook's photo handling are *not* working with PHP. That takes away from the supposed 4000. – Explosion Pills Oct 10 '12 at 13:35
  • @ExplosionPills: my point exactly; these few people that worked on storing gazillions of photos in FB, are just a tiny part of FB DevOps team. If they wouldn't have the whole PHP legacy crap, they would do with team 10 times smaller than they have currently. – vartec Oct 10 '12 at 13:43
  • The proof of the articulate man is in the correct usage of the pudding phrase ;-) – Jonas Kölker Feb 17 '13 at 18:27
  • Wordpress is so successful that the greate php devs still have not figured its not a good idea to put EVERY FILE in web root. And wordpress still has no ability to verify plugins for potential threats or prevent plugins from breaking themes and other plugins (Ever heard of "disable all plugins to check what's wrong"?). Even today on Wordpress5.5, most javascript injection attacks still work. Yeah, very successful CMS. – Rambarun Komaljeet Dec 11 '20 at 06:45
20

PHP has a sordid history. It's much better now that it was even a short while ago, but there was a time, a very long time, where a lot of bad practices and patterns were encouraged and difficult to avoid. There is an entire generation of terrible PHP code out there that is still kicking around, and to the extent that new programmers are learning by reading old code, they're learning bad behavior. PHP may not now deserve it's blackend reputation, but it certainly earned it nonetheless.

Your best bet for defending PHP is to carefully distance and distinguish the current state of the art from the history everyone is familiar with. You can say that PHP isn't a terrible language, but if you're talking to someone who's been in the industry for a number of years, their memory tells them otherwise.

Show them how the PHP team has learned from their mistakes and changed the language for the better. Gone are the days of magic quotes and register globals. Gone is the global-everything paradigm, and safe-mode, and mysql_escape_string. Explain to them that real PHP programmers always use namespaces and parameterized queries, they avoid deprecated functions and always put their library code outside the document root.

PHP has changed, and PHP programmers have changed. Which is why PHP is the wonderful platform it is today. Also, it's the only platform that you know your customers will have pre-installed. That's huge.

As a side note, I'd recommend against citing existing CMS engines and frameworks as a big win for PHP. You run the risk of them pointing out things like the Websense security study from 4 days ago showing that 94% of recent website infections were against PHP websites running software like Joomla and Wordpress. That's not the sort of company you want to be seen with. Instead point out that your code will be way more secure than all that other stuff.

tylerl
  • 4,850
  • 21
  • 32
  • 1
    +1 -- but -- but -- Claiming that your code will be "way more secure" than code peer reviews by several professionals isn't really going to hold much water to anybody halfway experienced in security. Everybody writes security bugs. The trick is just to fix them one step ahead of the bad guys. – Billy ONeal Mar 17 '12 at 15:47
  • @BillyONeal yep. The last paragraph is *meant* to strike you as a little... odd, and make you really re-think your approach to security. I did a lot of research on security of PHP vs non-PHP webapps, and the reports are disturbingly, massively skewed against PHP. That's not to say that PHP is bad, but security is a real concern. – tylerl Mar 17 '12 at 19:11
  • 2
    "Also, it's the only platform that you know your customers will have pre-installed" This statement seems utterly false to me, Not every server deployed is deployed with a LAMPhp stack, nor do any common linux server distributions I've tried ship with PHP pre-installed. However, every linux distribution I've ever used does ship with Python 2.x. I suspect some common utilities rely on it. – ThorSummoner Jan 08 '15 at 20:55
9

PHP is the COBOL of the web. Both languages get no respect, yet many people make their living building and maintaining systems written in them, and they are present in volume in almost every major computer system for their native world (i.e., the web and commercial business respectively). Both languages are looked down on by practitioners of other, more popular, languages, based largely on old and obsolete habits practiced by programmers who have since learned better and improved their tooling.

PHP should be so lucky, that it lives COBOL's life. COBOL has been around longer than anything but FORTRAN, and it isn't going away any time soon. There are plenty of COBOL programs in daily use that are older than the people maintaining them. It may not be "the new hotness", but there will always be money to be earned working in and with it.

Ross Patterson
  • 10,277
  • 34
  • 43
4

I think it may also be useful to understand the other side of the coin, and recognize PHP's shortages. While PHP has advanced a lot from being a template language, there are still many things that could be improved. There are some points where PHP is still lacking: Unicode, functional features, the organization of the standard library, the array and so on.

What I suggest is that - in order to make a constructive discussion about PHP strengths and weaknesses - it could be good to acknowledge all this. "Yes, I know that PHP standard library is not very organized. But if it was written today, it could make use of namespaces and object oriented APIs". "Yes, I know that the default array makes a little mess by mixing dictionary and array structures. But if one wants some better collections, one can make use of the SPL".

Your point of view will result stronger if you show that you know that the other people's arguments have some reason.

Andrea
  • 5,355
  • 4
  • 31
  • 36
2

Why?

Anyone who makes you feel you have to defend yourself (whether it's career, spouse, spending habits, etc.) is wasting their own time. You taking the time to defend yourself is simply humouring the wrong kind of people - now you're wasting your own time, as well as theirs.

Cut these people out of your life - you're better off without them.

J.K.
  • 13,063
  • 1
  • 40
  • 56
  • 4
    So, the answer is to take it personal and ignore it?. This is a cultural problem, I'd rather address it and try getting my arguments better and more concise to shoot down ignorance. – dukeofgaming Mar 17 '12 at 04:36
  • 3
    In a vacuum, I agree with your advice here, but PHP is indefensible. I always marvel at how Mark Zuckerberg succeeded *in spite* of PHP's awfulness: http://www.codinghorror.com/blog/2008/05/php-sucks-but-it-doesnt-matter.html – Jim G. Mar 18 '12 at 08:32
2

In order to address the "PHP is a bad language", you have to figure out why the individual in question thinks it's a bad language. Maybe (s)he worked on a bad project written in PHP. Maybe (s)he just doesn't like prefixing their variables with $. Maybe they themselves have attempted to use the language and written unmaintainable mess. Many programmers coming from other programming languages see PHP and see a mess, because what makes sense in PHP does not really make sense in other language or on other platforms. For instance, in PHP, arrays are the "duct tape of the universe", and are used to accomplish pretty much anything, while in other programming languages such a thing would be absurd.

I would suggest a combination of the answers here.

  1. As tylerl said, you have to show that modern PHP is significantly better than it's older cousins. Gone is the nastiness of create_function. Gone is the jungle of calling include manually everywhere.
  2. Acknowledge that there are faults in PHP. There are faults in every programming language. Saying otherwise will make many serious programmers completely ignore your response as being a "fanboi".
  3. Show people things that are easy in PHP that are difficult in other programming languages. Programming languages are designed to make some tasks easy, which necessarily makes other tasks hard. C? Memory manipulation and bit hacks are really easy, and the language is really simple, but maintaining large applications is hard. Java? Doesn't have free, and everything is "OO-ish", but the runtime is large and OO can be limiting. C++? Lets you make types that behave exactly like primitive types (e.g. int) in the language, but that comes with large amounts of complexity. PHP? Makes it really easy to start off without much programming knowledge, but as a result has lots and lots of garbage code posted on the internet.
  4. Acknowledge non-language advantages of PHP. There are still many things in PHP, as a language that can be... annoying to work with. But it's easy to configure, easy to deploy, and comes with a large set of great libraries that you can "plug in" to without much additional work.

There's a place for every language. Choose the language to suit the problem at hand, don't try to shoehorn a preferred language into places where it does not belong.

Billy ONeal
  • 8,073
  • 6
  • 43
  • 57
  • 1
    -1: Why are you trying to defend PHP? It sucks: http://www.codinghorror.com/blog/2008/05/php-sucks-but-it-doesnt-matter.html – Jim G. Mar 18 '12 at 08:29
  • 2
    @JimG.: Because that's what the OP asked me to do. I'm playing devil's advocate here; I really despise working with PHP myself. But just because a system is annoying to work with does not mean that there are no good things about that system. One can learn even from major f\*\*\* ups. :) – Billy ONeal Mar 18 '12 at 22:55
  • @BillyONeal Why do you hate working with it? Deciding on things myself. – johnny Oct 21 '13 at 03:27
  • @Johnny: Mostly, just being a scripting language which is ill suited for building large systems. Scripting languages are great for rapid prototyping, ease of deployment, and come with large standard libraries in the box. But building large systems with them often results in unmaintainable mess due to an inability to enforce compile-time checks and constraints. The very things that make PHP flexible and good for scripting scenarios (e.g. variables are untyped) make it difficult to build systems with more than a few people using a component. – Billy ONeal Oct 21 '13 at 04:21
  • @Johnny: To clarify -- I'm not saying that building large systems with PHP is impossible -- Facebook and Co. are proof positive that it is very possible. Just that it ends up being more difficult than with languages that provide better compile time syntax and semantic checks. – Billy ONeal Oct 21 '13 at 04:21
  • @Johnny: You also have to consider what PHP was designed to do -- embed small bits of code in web pages. If that's your use case, than PHP is a *great* platform as a "templating language," because its script nature meshes well with the way web pages work. The problem is that people use it to build things beyond the frontend processing for a web page, for which it was not designed and is ill suited. – Billy ONeal Oct 21 '13 at 04:27
1

There is no short and sweet one-liner you can bust out to convince people of the worthiness of PHP and its developers, but you wrote a very convincing argument right before you asked the question.

CFL_Jeff
  • 3,517
  • 23
  • 33