"Nothing is always absolutely so".
What is this article about? I want to show you modern PHP and the reasons to think that PHP is not so bad. From time to time I hear that PHP is obsolete, slow and that the core developers do nothing with PHP’s strange behaviour in different cases. If a programming language is not maintained, it always means that this language has no new features, has no different solutions from corporations that use this language in their projects, community, stable versions and updates from 3rd party companies. Any programming language often has its own weaknesses. Usually core developers and community try to fix those weaknesses, find the best solutions for different tasks and optimise memory and CPU usage. In this article I won’t talk about PHP in details. Let me just tell that we have everything we need for thinking that PHP evolves and can be better in future.
If you prefer listening to reading, we invite you to check out a webcast below: it's dedicated to the same topic.
Criticism of PHP
PHP is one of the most criticized languages. Usually a large part of critics are people who have experience of working with the older versions (lower than 5 or 5.4). It always goes this way. I don’t accuse those people and don’t say that they are incompetent. But now PHP has a lot of changes that make it relevant for writing a fine code and for using it in big projects. All languages have some limitations and problems, particularly if we talk about web-languages. PHP is not a new web-applications market player. Yes, we had many problems in PHP core in the past. But the large part of those issues were solved. Take a look at what PHP is now.
PHP is simple. And it always saves time at the development stage. Next point shows why PHP is good not only for beginners. If a language is simple, you can write an understandable code. You will spend less time on examination of the code of others colleagues or the 3rd party developers. You can fairly claim that if the language is simple it can lead to a big amount of projects with the bad code and weak places. Still, we all know that serious projects always require good developers. At least we want to believe in that.
PHP has standards. A lot of people think that they are limited by standards and have no profits. I don’t want one more discussion about whether we need to use standards or not. Let’s just take a look at positive sides.
The fact that PHP has standards means, first of all, that we have a useful tool for controlling our code. A coding standards document tells developers how they can write their code. Instead of each developer using his or her own style, code is written according to the standards outlined in the document. This helps to make sure that a large project is coded in a consistent style: all the parts are not written differently by different programmers. This solution not only makes the code easier to understand, but it also ensures that any developer who looks at the code knows what to expect throughout the entire application.
But, of course, it’s just recommendations.
General standards are the following:
- Basic Coding Standard
- Coding Style Guide
- Logger Interface
- Autoloading Standard
- Caching Interface
- HTTP Message Interface
Full list is here.
OOP in PHP
Yes, this is not an incredibly new thing, but it’s required now. It has many improvements and it works much better than before. PHP object-oriented model was completely rebuilt in the 5th version. Traits, namespaces, interfaces, member variables and more other. All of what you need from object-oriented programming features is available. It was documented and can be found here. You also can read more about OOP changelog there.
PHP has its own package manager. And it’s one of the best package managers ever. Take a look: it has a big official repository (packagist.org). Packagist is really good - it is easy to use and it has a lot of packages. Packages usually have updates and fixes. Some statistics about packagist is presented below.
Total amount: more than 109 476
Downloads: more than 2 732 219 178
Frameworks and CMS
You can find different PHP-frameworks (Symfony, Zend, Phalcon, Laravel etc) and CMSes (Drupal Wordpress, Joomla and other). Some of these projects are supported by big corporations like Facebook or Twitter. Why is this important? Indeed, if PHP is so bad and weak, why we can see a lot of projects written in PHP? Why does it have a lot of different libraries, modules and bundles? All of those platforms mean that PHP is quite relevant for serious big projects.
A collaboration between core and frameworks’ developers was improved. Some frameworks’ developers introduce a lot of their own solutions for different cases (for instance, you can remember the Facebook’s HHVM). It's better for improving the PHP сore. On the other hand, it means that we have a large amount of free libraries and modules that we can use in different projects and with different frameworks. For example, the usage of Symfony components: it can be integrated with any other platform.
Let’s sum up the written above together. PHP has a healthy ecosystem and trend for improvements. It is related to an amount of core-developers or companies that can improve features and resolve issues related to PHP’s core. And as a result we’ve got a 7.0 version. That was a big release: the obsolete things have been removed, new positive core improvements that can make your coding process easier have been added. Full list of features you can find here.
Also I want to notice that if technology is obsolete – nobody will use that. We have enough examples of this – Flash or SilverLight by Microsoft. If we want to understand more, we should take a look at some popular projects written in PHP. So, let it be Drupal.
Drupal as a project written in PHP
The only way to understand how much better the language is now, take a look at any application written in it.
Some statistics from netcraft:
Drupal core developers try to follow the trends. Now PHP has an object-oriented model. The new version of Drupal has started a transition to the complete use of OOP, patterns, code separation into layers (models, controllers, views, database-layer etc).
The procedural programming and hooks used when OOP in PHP was not completely introduced are no longer relevant. Now we can see a lot of new concepts in Drupal. The 8th version will not integrate a complete usage of OOP and the partial legacy of a procedural code still remains, but it will be implemented in Drupal 9.
We can see that Drupal 8 uses Symfony components. It is always easier and better way to use existing solutions. In addition, after a certain time some components will get a feedback from developers using Drupal in their projects. Thus, there is a positive trend and the transition to a completely different understanding of the ecosystem. Those feedbacks can be productive both for individuals and for Drupal.
We have a lot of field types at the core that weren’t added before: Entity Reference (allowing communication between the content), Date (for events), Link, Telephone, Email, Picture. Configuration system was completely rebuilt and now the setup data is stored in the files instead of a database. It makes it easy to export / import settings, use different settings for development.
And we have a large list of used Symfony components. I think these instruments can help you to understand what things are available on the platform.
A complete list of components and features you can find here.
"Let me say it again:
PHP is probably not the best language out there,
and I'm the first one to scream about its quirks,
but PHP is the best web platform... ever".
I can’t say anything better than Fabien, but I have my 2 cents to add. Somebody may think that one platform's evolution is not important for a language. Or somebody may think that all processes happening with language, developer and platform are standalone things. But this is not true. If you want a good language with modern features you also need to be modern. Projects that were written in this language are what can move this language forward. It is usually the only thing that can befriend core and framework developers, force to research new areas and make this language better.
In my opinion, the closed projects creation is not a right way if you want to take any benefits of the community and language. Drupal is trying to get rid of it and enter the market of big projects. It is important to support good projects, it is important to participate in the community life. Perhaps right now something important is happening to PHP and its community, and they are standing on the threshold of an important step. Maybe that will be determined in the nearest future.