Just yesterday I read a very interesting
PHP post
: a fractal of bad design (Russian version
on Habré -
approx. Transl. ). This controversial and provocative topic is widely discussed by the entire PHP community. To be honest, there are both really good positions and remarks, as well as frank errors that do not allow to see the whole picture.
Minor bugs
There are a lot of mistakes in the post and in general the author confuses God's gift with scrambled eggs. Let me highlight the main ones:
- No debugger - PHP has xdebug, which works great as an interactive debugger.
- There is no support for threads - this is true, but he notes this for a flaw when I find it positive; because the application life cycle begins with a request (I will cover this thesis in a little more detail)
- == useless - yes no, it is very useful if used in the right way. Yes, I agree that I use it less and less, but when you need it, it is useful ...
- Visibility problems with global variables - it finds something outlandish about it. Frankly, for me this is one of those things in which PHP is superior to almost all other languages. If you do not see global $ var inside a block, you know that the variable is local. Therefore, simply by looking at the function declaration, you can immediately evaluate what the external environment should be without tracking each individual variable (and do not ask your IDE to do it for you).
- Constants are defined using a function call - this is true, but the author forgets about the syntax `const FOO =" bar ";`, which is valid and is not a function call.
- Static variables within instance methods are global — this is true, because this is exactly what they are intended for. In Python, we would use `obj .__ class __. Varname` ...
- PHP is tied to Apache - this is frank nonsense: there are a lot of applications that do not need Apache. Apache is simply configured on default on most platforms with mod_php. But for me, setting up nginx + FastCGI is much easier than setting up mod_php under Apache.
- There is no easy way to “separate” a PHP application and its dependencies from the rest of the system - this is not true, as there are suphp and FastCGI; it's really really easy to run several different PHP instances running on different versions. Yes, in fact, with mod_php you have to share Apache instances, but there are other ways to organize a server than mod_php, so it’s not entirely fair to write off Apache restrictions on PHP.
- The features section - from that moment on I was lost. Until then, he spoke about the peculiarities of the language (and I would agree with the majority). But from this place begins the conversation about libraries and frameworks. Yes, there is no template system in PHP. But is it in Python or Ruby? In Django and Ruby on Rails, but what about Zend and Symfony? In PHP, there is no XSS filter, but there are none in Python and Ruby, only in frameworks. PHP does not support routing, but does Python and Ruby support? But there is a dev server . And support for interactive debugger (xdebug). And the same nonsense with security issues.
In general, out of all the big post, there are few points that can really cause discontent. It says quite a lot, but with such a pompous style it is not very pleasant reading.
My opinion
')
In fact, I agree with most of the writing. PHP is inconsistent. Verbose. There really are examples of inappropriate behavior. He has a lot of problems. Sometimes he is ugly. Sometimes he is clumsy in everyday life. Much leaves much to be desired.
But at the same time, it is unusually powerful. It is easy and simple to write a working application. Really easy to create a large-scale project. Easy to expand. And what is really simple is to get help (on the Internet you will be supported by one of the largest and most active programmer communities).
However, there is one thing that does not add to the popularity of the language: the ability to use non-developers. Just take a look around at open-source web projects and you will understand that PHP is a victory. I mean this whole CMS market, in which competitors for PHP simply won’t get a gun shot (Wordpress, Joomla !, Drupal, vBulletin, MODx, TYPO, etc.). Look at any network services market, and PHP will dominate there (or just have the strongest influence). The thing is, deploying a PHP site is ridiculously easy. So simple that even non-developers can do it.
As Brandon Savage says:
It's About The Customer . And this is the big piece of cake that was missed in the original post. In fact, from the point of view of a PHP developer, something is missing. But since when does the developer determine what is successful? If the developer had determined this, then software like Wordpress, jQuery and Jenkins / Hudson would not have achieved such success (for their source codes are under a characteristic quality issue). But they achieved it because they solve the problem and solve it well.
The thing is, PHP has many advantages over other languages. Here's just what came up in my head:
- HTTP is a first class object. No other popular languages provide this. Neither Python, nor Ruby, nor C, nor JavaScript. PHP has built-in support for HTTP at a low level. You may argue that this is not so optimal, but it is first class. You do not need any libraries or frameworks to speak HTTP.
- SAPI is a first-class object (Server API, mod_php vs CGI vs FastCGI, etc). This means that PHP was designed to be behind a stronger server. It also means that the transfer of code from the CLI to the server API is trivial (you just need to see how the request variables are obtained). There is no need to use libraries or frameworks to interact with the server. WSGI in Python, in principle, eats its bread for good reason, but you still need to connect the library to communicate with the server. This makes PHP quite simple to build a foundation for web applications.
- The life cycle of the application from request to request. In the original post it was noted as a negative aspect. Each new request re-launches PHP (well, not all PHP, but your PHP application) This is a good thing, because (quote from Rasmus Lerdorf , the creator of PHP in an interview ) "The shared-nothing architecture of PHP ... leads to infinite horizontal scalability in the language itself. ”(literally:“ PHP architecture not allowing anything to fumble ... leads to infinite horizontal scalability of the language as such ”).
- Just a huge user base. Yes, other languages have a lot of followers, but no one comes close to PHP. And personally, I think this is the most significant aspect of all. This is an ark full of knowledge on how to expand PHP and how to solve almost any problem. If you know what you are doing, then you will find everything you need.
These 4 reasons are enough for me to consider PHP as my main language. I know and actively use Python and server-side JS (node.js at the moment), and I am familiar with several other languages. But I still stick to it and will stick to PHP for my core projects, because although it’s not perfect, it works ...
And your thoughts?