10 reasons why PHP is better than Python

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” – Bjarne Stroustrup,

People wonder: Did he really say that? Yes, he did. If you wonder who Bjarne Stroustrup is: He created the C++ programming language. Many people believe that Python is “pretty cool” and PHP is “really bad”. But as we all know, there is truth in the saying:

It’s a poor carpenter who blames his tools.

I believe both good and bad software can be written in any language. And I should probably also quote Joel Spolsky who calls “language wars” a “fruitless debate”. But nevertheless, if you program in PHP and run into one of these Python “evangelists”, then the following list may come in handy.

10 reasons why PHP is better than Python

  1. Python hosting, hard to find and expensive, while cheap PHP hosting is everywhere.
  2. Python cannot be mixed with HTML (needs a template library), while PHP can.
  3. Python has no proper encapsulation (private keyword), while PHP has.
  4. Python is hardly used in the real world, while something as big as Facebook is built on PHP.
  5. Python has a great community, but it is not comparable to PHP’s.
  6. Python has some books and tutorials, but PHP has way more of them.
  7. Python does not have the live docs (famous forum-like reference manual) like PHP has.
  8. Python does not have a steep learning curve, but PHP is still easier to learn.
  9. Python indentation for code blocks is prone to errors, while PHP uses curly braces.
  10. Python lexical scoping is a mess (‘global’ and ‘nonlocal’ keywords fix this), while PHP behaves as expected.

To wrap up

PHP has come a long way. Today it is a mature language that executes fairly speedy. Agreed that it has some quirky naming of it’s built-in functions, but hey.. that’s the price you pay for backwards compatibility.

Hint: Make sure to also check out this page on Python.org that is a good reference when comparing Python to PHP.



21 thoughts on “10 reasons why PHP is better than Python”

  1. You are completely missing the point.

    The first problem is: reasons you’ve listed are stereotypical rants that young PHP developers say. Reasons #2 #4 #7 #9 are just false. For templating here you are: http://tornado.readthedocs.org/en/latest/template.html, the others you could find yourself. Moreover, reasons #3 #6 just don’t matter (who cares about quantity of books on PHP? Do you need to read them all? functions beginning from _ not being imported is not enough for your encapsulation needs or you are being theoretical again?), and #5 #8 are completely subjective. Please don’t say anymore of that.

    The second problem is: you don’t understand that language is just a tool to solve your problem. You should find a suitable tool for your problem, not vice versa. While it is definitely easier to build classical websites (no websockets) in PHP, you won’t be able to write a system daemon or SMTP server or a concurrent messaging server in PHP.

    You shouldn’t concentrate on one tool, it is slowing you down. Python is great when it comes to science: https://wiki.python.org/moin/NumericAndScientific, you won’t find this number of scientific packages anywhere but in Python. It also, in my opinion, is much better suited for API servers than PHP with its perfect Flask http://flask.pocoo.org and creepy but pretty fast Tornado http://www.tornadoweb.org/en/stable/.

    There are dozens of languages that everyone should use in their specific domain. Erlang for stable concurrency systems, Go for productive network and system programming, PHP for building simple websites, Python and Julia for scientific applications, Lua for embedding, Perl for parsing and scripts, Clojure for general-purpose language with immutable structures and concurrency, Haskell for learning great new ideas.

    Programmer should be able to program on everything, that’s the difference between a programmer and just a person who needs a website.

  2. @Yegor: Thank you for your elaborate response. Well done. One remark on a point where we do agree:

    “you won’t be able to write a system daemon or SMTP server or a concurrent messaging server in PHP.”

    While you technically are “able”, as PHP can call all posix calls needed, it is probably better if you don’t. 🙂

    Check out “nanoweb” and be (positively) amazed: http://nanoweb.si.kz/

  3. I can’t speak about Python, but as a long-time PHP developer, I can state that the language is not without its flaws. You see variance in naming conventions within groups of functions (str_replace, strpos, to name a couple). Also there are needle-haystack param reversals found in PHP (in_array(needle, haystack [,…]), strpos(haystack, needle [,…]). IMHO, these aren’t newbie friendly features. Hmm, as I search — trying to figure out if the difference is, say, the php version < 4 vs > 4. I find a far more comprehensive list from a better dev: http://phpsadness.com/

    Yowza. This one explains one nagging bug I could fix, but never quite understand: http://phpsadness.com/sad/30 (ternary operator associativity).

  4. Heroku has a free tier, and supports Python. You can get a Linode for ten bucks a month, and run whatever you want. Or there are these I guess: https://wiki.python.org/moin/FreeHosts

    Mixing code with your templates is a poor idea. You may notice that most mature PHP projects use template libraries, too.

    I don’t like `private`. It has two uses I’d consider valid, and neither of them apply to Python: 1) preventing external code from wrecking your memory space by doing unexpected things with your internals, 2) wrapping everything in getters and setters. Python and PHP don’t do direct memory access, so 1 isn’t a concern. Python’s @property decorator lets you add validation and whatever else you want to attribute assignment, so 2 doesn’t apply.

    It’s interesting that you mention Facebook, when Instagram is written in Python. So is YouTube (and Google uses Python a lot internally). So is Yelp. So is Reddit. So is Dropbox. So is the Washington Post. I’m sure the list goes on, but it’s hard to tell what any given website is using unless the developers tell you.

    Most of what I’ve seen in the comments on the PHP documentation has been absolutely atrocious advice, so I would consider Python’s lack of an equivalent to be a feature. Take it to StackOverflow, where people can vote you down if you’re wrong.

    In some seven-odd years of writing Python, I can count the number of indentation errors I’ve had on one hand. My editor indents or dedents by an entire indentation level at a time, so there’s not much opportunity to screw it up. But look at it this way: if you indent your PHP code, you’re wasting time and vertical space writing braces. If you don’t indent your PHP code… well.

    PHP also has a `global` keyword, for exactly the same reasons as Python.

    Your other three grievances are merely “Python has good community/books/learning curve but PHP’s is still better”, which leaves nothing factual to dispute.

  5. @Eevee: Thank you for visiting and commenting on this blog using IPv6! Great writeup from your side. Good to see a Pythonist’s point of view.

  6. @Ark: Thank you for commenting. Would you care to share your reasoning or is it just a feeling?

  7. @Arnold: Thank you for the link, great article! Do you agree with the article that Python is worse?

  8. “@Arnold: Thank you for the link, great article! Do you agree with the article that Python is worse?”

    The article doesn’t even say that. You are a troller.

  9. @Kevin: Thank you for your reply. Indeed, the article only helps you argue that PHP is better. I hope you liked it!

  10. It’s mostly a case of “horses for courses”; but there are a couple of issues :
    a) Utf-8 – in PHP one must remember to use the multibyte mb_ functions; Python 3 works in unicode so one must remember to explicitly encode strings for output.
    b) Python will execute fsync to secure data files; in PHP better to use SQLite or something, unless the web host supports the eio extension.
    c) PHP much easier to deploy.
    d) which will still be around in ten years’ time?
    Using these criteria the answer is ?????

  11. @Biggles: Thank you for these insights. I think Python 3 got UTF8 quite right, while PHP may not be up to that level (yet).

Leave a Reply

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