DEV Community

Cover image for Using PHP for good - why it is bad and why it might work for you
Dhiana Khim
Dhiana Khim

Posted on

Using PHP for good - why it is bad and why it might work for you

PHP has received so much hate over the years that it is one of the most infamous programming languages ​​on the planet today, only in part because of how popular and ubiquitous it is (+ 70% of websites), but it can be a force for good. ...
There are many posts about how easy it is to be wrong, how inconsistent the language has become , how detrimental the lack of hard data type checks has been, and how the amount of dark magic in it makes it slow, unpredictable and overall. not suitable for most use cases. This article is one of my favorites on why PHP is bad as a language.

It's worth mentioning that companies like Facebook have made efforts to improve PHP (for example by creating a Hack) into a compiled language, and there are large frameworks that can be used for more structure and confident coding. But the virtual machine used for jailbreak is also known for its resource intensity.

Also, type hints do exist in PHP , but they are optional and often ignored by newbies and online sample code.

Why is this bad for novice programmers?
It's very easy to start using it wrong, go down the rabbit hole, learn all the wrong tricks, tricks and gimmicks, and as a result, write some pretty terrible code and keep those habits in your career. As a stark contrast to the comparison, Java employs OOP, and Haskel leaves you no choice but to learn functional programming while Scala is their brain .

In PHP all this and more can be used at the same time, the wiki page itself mentions imperative, functional, object-oriented, procedural, reflexive . This is good if you want to stick to a style you already love and understand, but not so good if you want to learn programming during your formative years. The language is not particularly good for any of these paradigms, so while you can apply them all, it is rather verbose and lacks the full feature set like languages ​​dedicated to their art.

If you are new to programming and are currently learning PHP, the point is not to give up, but instead explore software design patterns and a language like C ++ / Java or similar along with it (one that is compiled and with type safety). This is to ensure that you learn programming best practices in general and be skeptical of what PHP provides, developing your ability to compare it to other languages ​​from the beginning.

Disclaimer: I love PHP
I use it almost weekly for quick prototypes or for a thin layer of logic for the UI needed for a new project. However, I gave up on using it for business logic . Some of these projects can be found on my GitHub, including browser games .

Am I going to ditch PHP?
Not. I'm not planning on ditching PHP anytime soon, and I think if you have some experience with it, you might want to consider it in your projects as well. This is mainly due to the fact that I have been using it for over ten years and now it has become part of my programming toolbox.

Is it worth learning PHP as a programmer?
If you are a seasoned developer using other languages ​​and have a full stack, then you already have experience with your favorite user interface structure of choice, where you can set up very quickly from scratch. In this case, I personally see no reason for you to consider moving to PHP, unless you are moving to a role that requires it. If you want to learn a new UI technology for the web, it's still a good idea to go beyond PHP if that's not your role. I prefer Angular and React, sometimes making them talk to the PHP server side, avoiding PHP taking care of creating HTML structures.

Is PHP worth learning because it's everywhere?
From experience, learning PHP as it is widely present in the web ecosystem is not a sufficient reason in this case.
It is not at all popular outside of web development, but is popular enough there to make it to the top lists of common programming languages because of how widespread it has become in the past, especially with frameworks like Wordpress and some of the mainstream forums. Depending on which website you are reading, it is currently either in decline or gaining traction, but is still present in the world of web developers. According to the index TIOBE she won in 2004 and is now ranked 7th.

It will be easy for you to master if the need arises, using your solid foundation from other languages ​​and software design skills. Portable software development and architecture skills (system design, caching, scaling, design patterns) are usually of great value, and once you take control of a more difficult language to learn and use, such as C ++ or Java, it will be easier for you. to implement best practices in PHP, where there are fewer default controls other than human-written code.

Top comments (1)

kwnj profile image

Nice article.

I was lucky when I started at a small web-dev shop. We didn't use any existing frameworks, but built our own from the ground up. It allowed us to learn all the ins-and-outs of the language and enabled us to understand the quirks of PHP. The most important thing we learned was when to not use PHP. It's easy to get caught up in a language or framework and forget that a simple bash script might be more efficient.

These days if I have a PHP project, I often use Laravel. It uses common design patterns and utilizes type-hinting and dependency injection. Plus, it's very rapid to develop especially if you already have a solid understanding of PHP.