Which is Better - PHP or Python?

Firstly, define “better”? That’s an incredibly subjective term that depends entirely on what you’re looking for. Do you mean faster? More widely used? Easier? Offers greater employment prospects? Greater availability of frameworks and libraries? I could go on.

PYTHON

What are Python’s strengths?

  • Vast array of built-in and 3rd party libraries/modules specifically for web development and server management (server management applies to web development too).
  • Those 3rd party libraries are well designed, well maintained, easy to install and powerful.
  • Ease of development. If you’ve ever programmed in Python, you know how easy it is.
  • Django is very powerful. It helps replace JavaScript and PHP.
  • [OPINION] Personally, I hate PHP and JavaScript. They’re frustrating to use and both are vulnerability prone. PHP more because of flaws in the language; JavaScript because of flaws in the weird-as-hell specification that lead to poor interpretations of how the JS engine should be implemented.
  • Fully object oriented.
  • Great for data manipulation and machine learning (can be important if you’re providing targeted advertising on your platform).
  • With the right framework, and modules (included as standard), you can properly and nicely integrate with a database server and auto-generate queries for your site.
  • e.g. If user is searching their account for a specific license key, the framework handles that by translating what the user’s doing into an SQL query.
  • e.g. #2: If the admin is searching for a customer by email address, the framework will translate that into an SQL query, then translate the results back and display them in CSS-formatted HTML.

What are Python’s weaknesses?

  • Slow. Like really slow. Slower than Python fanboys like to admit. As Oluwasegun said, PHP is up to 3x faster (sometimes more, sometimes less, depends).
  • When you use it for development, you can’t really think of it like you’re using Python: You’re using a framework (e.g. Django). So learning Python isn’t enough, you have to learn the framework too.
  • Python is nowhere near as widely used as PHP, so its employability factor, specifically in regards to web development, is much more limited. I heard a stat that ~80% of all websites use PHP - I can’t verify the stat, but it wouldn’t surprise me.
  • This kind of goes hand-in-hand with slowness, but needs to be addressed separately: Resource use. Python hogs resources much more than PHP. You’d think, if it utilized so much of the available resources, that would actually maybe help to speed it up…… No, no it doesn’t.
  • [Opinion] The OOP aspect of Python is abysmal. If you’ve ever done any OOP in a language like Java, C#, or C++, you’ll understand why I hate it. Any language that relies on this and super() hasn’t done it right. It makes you code look confusing as hell, obfuscates the whole process and makes the developer prone to errors. It’s just not necessary - the whole aspect of the language feels (as I think I’ve said elsewhere on this site) like it was bolted on, with a hammer, by a blind fish…. as an afterthought. And guess what? It was! Alright it wasn’t bolted on using a hammer, by a fish. But it was an afterthought and wasn’t initially intended to be part of the language (it wasn’t initially included).

It’s a poor and restrictive implementation of OOP. Again, Opinion. Some people like it, but they’re usually the ones that say C and C++ are difficult and confusing.

All in all, that’s not terrible right? Personally I think the biggest issue in the above is ‘market share’ in comparison to PHP, from an employability perspective anyway.

PHP

What are PHP’s strengths?

  • Very fast.
  • Fully object oriented.
  • Used in a vast majority of back-end web-services and ‘behind the scenes’ functionality of websites.
  • Integrates nicely with SQL servers and virtually all flavours of them.
  • Auto-generates queries to the database (see Python section of example of what this means)
  • Wonderfully diverse built-in functionality that is designed for web use.
  • Lots of PHP web API’s available that further extend what can be done.
  • Lots of these are designed specifically for use with PHP and cannot be used with Python & Django e.g. Many e-Commerce API’s

What are PHP’s weaknesses?

Oh boy. There’s some real humdingers:

  • [Opinion] The syntax is friggin awful. Yes, that is an opinion, but it’s a very widely shared opinion. Each and every single PHP programmer that I’ve ever spoken to has held this opinion too. If you’re not already familiar with it, check it out.
  • SQL injection attacks. See the link below for a detailed explanation of what it is, why it happens and how to solve it using PHP:
  • Prevent SQL injection vulnerabilities in PHP applications and fix them
  • Remote Code Execution: A bug in a PHP application may accept user input and evaluate it as PHP code.
  • Cross-Site Scripting (XSS [X = Cross]): Stored XSS and Reflected XS
  • Authentication Bypass - Technically a developer error, but the language itself makes it really, really easy to make this mistake.

I could go on with more, but here’s a link instead:

    https://www.wordfence.com/learn/understanding-php-vulnerabilities/

    [Opinion] OOP is just as bad as in Python. Possibly worse due to the syntax. It still uses this (but it’s actually $this)

All in all, those vulnerabilities are pretty darned awful, but they’re mostly due to developer error. Get to know PHP well and research not just ‘How me do a PHP develop’, but “PHP development pitfalls” and “PHP vulnerabilities” then it won’t be such an issue.

All Together Now

So what’s the ultimate conclusion to be drawn here? Well, despite what die Python fans like to say, Python cannot fully replace PHP, due to the presence of common PHP-only API’s, and the industry dominance of PHP.

I know I’ve already gone on for ages, but this is my final point and it’s really important to state: The idea that developers should be picking a “one best language because it’s bestest” is a massive failure of both the modern education system, and junior [young] developers. In order to be truly proficient in any field of development, be web, app or software, you’ll need to know multiple languages. The same holds true to be reliably employable.

So in conclusion it’s not about which is better, it’s about understanding where and when to use them. And, for web development, the BARE MINIMUM you should learn are the following:

  • HTML
  • CSS
  • JavaScript
  • PHP
  • JSON (replace XML)
  • SQL (MySQL, Oracle, MS SQL are the 3 main) - beware of different ‘flavours’
  • Python
  • Web hosting admin panel

The above are absolutely non-negotiable for a career. Optionally, learn Java too. It’s useful for web apps.