PHP – a bad programming language – Dark side of PHP

I’m a web developer by profession and have been involved in PHP development for last three years. PHP is very easy to learn and program in. But what i think, PHP is a incomplete programming language as well as a bad programming language which gives bad practice for the programmers.I can point out why a most popular programming language used in Internet sucks and have a lots of dark side

1) No need to define and declare variable – In most of the programming language, you have to declare the the type of variable and define it before to be used in the code but in php you don’t have declare the type of variable before using.Although, it make easy for the programmer but ita bad practice at all for a genuine programming concept.

2) No Strict data conversion – Well as you see in java, if you try to con cat a integer variable with a string variable you’ve to convert it into string variable before con cating with string otherwise compiler throws exception. But, in php if you’ve to do so you don’t have to do any kind of data conversation, which you might say easy for programmers but what i say thnat bad practice for programmers.

3) Bad Recursion – Recursion is the mechanism in which a function calls itself. This is a powerful feature which can make something complex something simple. An example of a function using recursion is quick sort. Unfortunately, PHP is not good at recursion. Zeev, one or the developers of PHP, says this: “PHP 4.0 (Zend) uses the stack for intensive data, rather than using the heap. That means that its tolerance recursive functions is significantly lower than that of other languages.” . A good programming language should provide good recursion support.

4) No namespaces – Suppose someone creates a PHP-module that can read files. One of the functions in this module is called read. And someone Else’s module can read web pages and also contains a function read. Then it is impossible to use these modules together because PHP will not know which read function you want.
An easy solution to this is namespaces. It was a suggested feature for PHP 5, but unfortunately it didn’t make it. Now, without namespaces, every function has to be prefixed with the module name, to prevent name collisions. This leads to terrible long function names like xsl_xsltprocessor_transform_to_xml which makes code harder to write and read.

5) In consequent function naming convention – Some function names consist of more than one word. There are three conventions for combining these words:

a. Glued together: getbidsbyday
b. Separated with underscores: get_bids_by_day
c. Camel case: getBidsByDay

Most Languages choose one of these variants, like java uses Camel case but PHP uses all of them. For example, it you want to convert special characters to HTML entities, you use the function htmlentities (Words glued together). If you want to do the opposite, you use its little brother function html_entity_decode. For some reason the words are now separated by underscores. Why is this bad? You know there is a function named striptags. Or was it strip_tags or stripTags?
Every time you have to look up what the notation is or wait for an error to occur and then open the php manual and search the function’s name.

6) Seldom use of Framework – A website without a framework which grows will eventually become a maintenance nightmare. A framework can make a lot of work easier. The most popular model for a framework is the MVC-model, in which layout, business logic and interaction with the database are separated.

Many PHP web sites don’t use the MVC-model. They don’t even use a framework. Although some PHP frameworks do exist (like Zend php framework, cakephp, Symfony). You can also write your own articles or manuals about PHP don’t say a word about frameworks. On the other
hand, JSP-developers use frameworks like Struts and ASP-developers use .Net, it looks like the concept of a framework is largely unknown by PHP developers.

Note : MVC stands for Model View Controller.

7) Slow – People thinks that Java is slow but it will be hard to know you that PHP is much slower! Look at this Computer Language Shootout. So how can PHP be used on all these popular websites with lots of visitors? It all because of caching. These sites use MCache and APC to get performance. It doesn’t proof anything about PHP, only that it’s cachable.

Finally, Php is easy to learn and development cost is low compared to other technology but being a true fan of programming language what i feel is that it sucks as a programming language.

31 thoughts on “PHP – a bad programming language – Dark side of PHP

  1. CruxOp

    I’m not sure that you know the difference betweeen static typing and dynamic typing.

    You’re too used to working in static languages like C/C++ and its variants.

    In PHP you don’t need strict type conversions because there are no strict types. If you want to *force* a strict conversion from int to string, you can, but its not required because in dynmaic languages type checking is the exception, not the rule.

  2. Nur

    most of comments are treditional like text book though PHP has lower control on server.

  3. Captian

    You call yourself a PHP guru? Where have you won this title?

    @1) + 2): It is a dynamic language. Look it up at wikipedia.

    3) Provide an example where you had problems with recursion.

    4) Namespaces are in 5.3

    5) I definitely give you this one.

    6) You just want to bash at PHP, do you? Why is this a fault of a particular programming language?

    7) So you are writting your websites in assembler?
    Seriously, do you think you can service a popular website without caching?

  4. Adrian

    Seriously mate, you’re lame…
    How do you have the courage to consider yourself a php and ajax guru? You’re lacking basic knowledge about modern programming languages…
    Are you sure you didn’t invented a time machine 10 years a go and jumped to 2007 this week?

  5. Andrew

    OOO! Look at me! I’m just someone who wants blog traffic so I’m going to bash PHP with my half-wit!

  6. Donald

    With the slightest amount of research you would have found that namespaces is going to be included in PHP 5.3.

    Keep in mind that PHP is still young compared to JAVA, ASP, python, c, c++. Not that any of those are scripting languages.

    And the PHP dev group never said that weren’t going to include namespaces.

    I will agree with you on function names there doesnt seem to be a naming convention that is follow.

  7. Roshan

    Thanks for the comments captian..but let me clarify you…

    You are right PHP is a dynamic lagugage but my poin is if a programmer starts career with PHP then he could most probably be unaware of the data types and converstions mechanisms which is the core conecept of the programming.
    And can you please provide me a link where i can find the codes related to php namespaces, i could find it in google as well.

    Ya you are right, a popular website need caching but you gotta better look at the links provided to view clearly that which one is slower

  8. Roshan

    well dude…namespaces are going to be included in PHP5.3 … but the thing is that it is not included yet and right now i can’t use namespace in my recent programming article is not concerned about future scenario..

  9. Masiosare

    Yep, sounds like you don’t know what you are talking about.

    The only one which I agree with you is 5.

    about (4) your example is at least, weak, PHP < 5.3 has 1 namespace, the global one.

    Why would you want to create two functions with the same name in the same namespace?

    You should be creating one function in its own class, OOP style.

    $csv->read() and $txt->read() won’t collide.

    and about 7) If you don’t know why an dynamic typed and interpreted language is slower than a static typed and compiled one, you should really go back to the school :)

    “You are right PHP is a dynamic lagugage but my poin is if a programmer starts career with PHP then he could most probably be unaware of the data types and converstions mechanisms which is the core conecept of the programming.”

    Ignoring your typos, how is that a problem with PHP if the programmer don’t even read the manual?

  10. OIS

    1. I can see from your spelling why you would want declared variables. Im hardly a perfect speller either.

    For fast development its easier without, and with proper tools like PHPUnit testing and a good text editor that should not be a big problem. If I find I have too much code somewhere I split it into manageable classes, methods and functions.

    2. This is not a problem as long as you’re aware of it.

    3. If you need to do some serious recursing, you should use another (compiled) programming language anyway imo. But I guess this will not be a problem for 99.9% of most websites.

    4. Namespaces are coming, and hopefully they’ll redo the functions you mention in your next point to something like use Zend::String; $array = String::ParseUrl($querystring). Also the randomness of which order the function parameters are in is annoying. I usually look up a function just to see which order the parameters are supposed to be in…
    Hopefully they’ll remove most of the global constants aswell.

    6. If you just write a guestbook to your family website its easier and faster in “pure” PHP then learning a framework. But bigger websites do use frameworks, in PHP as well as in other languages. Of course, they might be using their own framework instea dof something built by others.

    According to this page on wikipedia; PHP is second only to Java in a listing of well known (?) and used frameworks.

    7. PHP is good for caching, and its easy to communicate with for example java for data persistence.

  11. musher

    The only one of your comments I totally agree with is the one about naming conventions, unfortunately due PHP benig open source and community driven, it’s let itself down on this front. But I’d rather have the functions named differently than not at all.

    All the other points sound like bad programmers, not a bad programming language.

    1. If you want to define and declare variables, you can.

    2. If you want to do strict data conversion, you can.

    3. This I’m not sure on, but is it really your opinion…?

    4. Multiple namespaces are in the repository as people have said and if you want to avoid these problems now, you can.

    6. Plenty of frameworks out there, if you want to use one, you can.

    7. What’s wrong with caching? If what you’re saying is that it’s easy to cache data with PHP, that’s a plus point. A fast Java program is great, once you’ve built it. PHP beats Java hands down on development time, leaving plenty of time to implement caching 😉

    A bad workman blames his tools. Young programmers may pick up bad habits if they start with PHP, but without languages like PHP, some would not start at all. I spent 3 years at university developing in Java and still made all the classic mistakes when I started using PHP, becuase I was lazy, not because PHP is rubbish.

  12. CruxOp

    About the recusion.. please look at this:

    Direct Quote:

    [7 Aug 1999 12:25pm UTC] zeev at cvs dot php dot net
    PHP 4.0 (Zend) uses the stack for intensive data, rather than using
    the heap. That means that its tolerance recursive functions
    is significantly lower than that of other languages.

    It’s relatively easy to tell Zend not to use the stack for this
    data, and use the heap instead – which would greatly increase the
    number of recursive functions possible – in the price of reduced
    speed. If you’re interested in such a setting, let me know, we
    may add a compile-time switch.


    Since its 2007 now, I htink that the bug may have been fixed in PHP5 and beyond. Since its just a simple switch to use the heap and not the stack. 😉

    Though personally, I limit the amount of recusion I use in my programs.

  13. Jeremiah

    Wow, looks like someone put the PHP community’s panties in a bunch! People, don’t take it so personal.

    All the comments on this page, really just validate the general point of “PHP is a bad language that encourages bad programming practice.”

    PHP is VB 6.0 for the web. Extremely popular and made so you don’t need to know much of anything about programming to do it.

    I think the author does know the difference between static and dynamic typing, but prefers static. And so do I. It’s nice to know what kind of data-type I’m working with, especially when working with an API not written by me. It’s also totally absurd that not declaring variables is a strength of PHP. How many of YOUR hours were wasted on a bug to find out you mistyped a variable name…something a strict language would of caught instantly.

    We can all make spaghetti code in any language, but it’s dynamic languages like PHP that take spaghetti to the ultimate limit. It lets bad programmers be even worse. Software development is inherently a strict discipline, dynamic languages are a perversion of it. Didn’t anyone ever hear the 100 line rule? Anything more than a 100 lines should not be a dynamic script.

    It’s obvious that PHP was not developed with any foresight or planning. It’s as if it was some sort of disgusting orgy of “Let’s add more functions to PHP!”

    Anyways, PHP will continue to be popular as long as people continue to use it, no matter how bad it is.

    If you are a good PHP programmer, props to you…but don’t you feel like Michael Jordan in a WNBA game?

  14. CruxOp

    ^ To the poster above.

    If you’re a good programmer in one language… say C/C++ then you would be a good programmer in PHP.

    The reason people point out PHP as bad so many times is because it allows non-programmers to be fairly successful in their first stabs at this “web software thingy”.

    Is that a bad thing? No, I don’t think so.

    PHP also makes it easy for programmers of any language to feel comfortable. Ever wonder why there are perl functions and C functions all jumbled into the same language? Well at the time, that was who PHP was appealing to and felt the need to create functions for.

    Unlike most languages, PHP really did ‘evolve’ with each version to meet the current needs. It didn’t get started in an ivory tower like Lisp/Ruby, nor was it invented to appeal to a single group like Java with Enterprise-clients.

    Look at PHP today, and you’ll see a tendancy to include “real” programming features. PHP 5 brings classes. PHP 5.2 brings late static binding. PHP 5.3 brings namespaces.

    And if you really really want static typing, there’s a couple of spin-offs from PHP that give you just that.

  15. Dennis Wong

    I do a lot of programming with C/C++, Java, Perl, Python, and of course, PHP. I don’t love or hate any of them because they’re just all tools. Instead, I pick to use according to different requirements and/or situations.

    The author has his points… the namespace thing, function name convention, or even the class/object support. They all have problems. However, there is one thing that we all have overlooked and mistaken. PHP is by no mean a programming language, at least not by the purpose it was made in the first place. It started as a “template script language” and it was the users (web developers) who abused it and pushed it so hard that it became what we have today.

    The only thing I feel unpleasant about PHP is the PHP framework(s). The majority of the users claim that they use PHP framework(s) because they want their codes to be written in MVP model. Wait! Isn’t PHP itself a template engine? Look at all those bytes outside the “<?php … ?>” tag pairs! They all got printed onto the standard output! It’s only a matter of principles to write your code in MVP model. …sorry, I’m a bit off topic. I think I should stop here.


  16. Bijay Rungta

    5 is a very valid point.
    I couldn’t agree entirely to your other points..

    It’s all upto you.
    You can use techniques to work around for the other points laid out by you..

  17. Ernie

    I definitely agree with the author. PHP really do have some issues to say the least. I have to say I’m quite surprised that people don’t see PHP as slow. Some say it’s not because it’s cachable. Well, I’d say that’s proof of it being slow and need caching to be fast enough (as the author argue). Using caching and accelerator it’s possible to achieve in some cases about 5 times better performance. In my opinion that’s hard evidence that there are some tricks that can be applied which will give a boost in speed. Now I’m really wondering why this isn’t a part of PHP. If PHP is suppose to be fast, shouldn’t that be included by default?

    One thing that’s not mentioned here is I18N (internationalization) and Unicode. PHP is useless if you want any of that. For starters both mbstring and iconv accept Unicode code-point that really, really, really shouldn’t be accepted. For instance U+D800 to U+DFFF is perfectly valid even though no Unicode encoding is using it, because in reality it’s byte sequences that are used in UTF-16 to support astral planes (stuff above U+FFFF). Last time I checked, allowing such is regarded as a potential security problem (don’t ask me why). Even so, I’m quite curios to know which byte sequences this is going to be translated to in UTF-16. Yeah, and did I mention Unicode is a 16-17 year old standard or something? IMO this should be supported a very, very long time ago. Say at least PHP4 and definitly PHP5.

    Anyway, without proper support for Unicode, I18N is just about impossible to achieve. It’s not the only problem though. Proper support for I18N require locale sorting abilities, searching, to upper/lower case etc. none of it being remotely available in PHP. Mbstring doesn’t even have case-less matching! … and no, it’s not a matter of using strcmp and mb_strtolower. Case-less matching requires something called “case folding”, and that’s definitely NOT the same as lower case.

    The lack of Unicode and I18N in addition to in-consequent naming convention are the main reasons why I wouldn’t develop any major web-applications in PHP. It just isn’t suited for it. Maybe PHP6 will change that, but PHP6 is not going to be available for quite while.

  18. I am using PHP since last 4 years and i have never feel any lack of resources in it. This looks very simple for beginners but as you go in depth of php you will find alot about PHP.

  19. Audi Nugraha

    7) Irrational one. Ever tried yourself? I think you’re just fell in love with Java.

  20. Cenovis

    I’m someone who is coming from a mostly Java and C++ background and is in the process of learning PHP5. I understand what you mean by PHP being a bad language; too much freedom kills.

    Most people (even the internet hotshots posting here) need to be protected from themselves most of, if not all of the time. Java knows this, and ensures that the user does not accidentally shoot him or herself in the foot. PHP wants too badly to bite the hand that feeds it.

    Not to say that I don’t like the language, it’s very refreshing to have so much freedom. But for a serious application, or large scale website, I would definitely not use PHP. There’s a lot of naysayers here, but the overwhelming consensus elsewhere on the net seems to agree with you.

  21. alex downson

    well, i think you are not a good PHP programmer.

  22. Ari

    What do you get when you do this in php ?

    $a = ’54′;
    $val = $a[‘crap’];

    you get string ‘5’

  23. manibalan

    hey first of all you know that the PHP is dynamic language and specially used for web programming,of course its a open source.The only language very eay to learn and easy to work.i think you just not a beginner in PHP.check out the 5.3 version its include namespaces, late static binding, closures, optional garbage collection for cyclic references..etc…
    check out

  24. james

    Dont you ever use a spell check?

  25. maath

    Look at all the PHP fanbois.

    PHP is great for people who don’t want to learn programming. In 24 hours you can be a PHP Guru and unfortunately lots of people consider themselves “developers” because they have knowledge in PHP. The language is supported by hobbyist programmers and has a weak community. I hate the language, and refuse to use it, as it serves no purpose for a real programmer.

  26. php programmer

    Hey ARI

    What was you value for: $a[‘crap’];

    Doesn’t make any sense to me!

  27. I’m not a fan of PHP, Thanks for your comments

    Like JavaScript… I like weak typing, and dynamic objects, have no use of namespaces.

  28. Camel Case

    You sound like you know very little about software development. Perhaps you are self-taught, perhaps were trained in India. Whatever, it is because of folks like you who expound their ignorance that I can have a good laugh.

  29. PHP can be a bitch, but I love it and it gets the job done.

  30. Anyone else find it ironic that he is bashing PHP and yet his site is powered by WordPress? A PHP blogging system…

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>