📜 ⬆️ ⬇️

In defense of PHP

Recently, a stack has been created on stackoverflow in which the author claimed that PHP is not a good language and asked to convince him. As arguments, he cited several arguments that were consistently commented on by another participant. A free translation of this is presented below.
Personally, I fully agree with the responders and I think that all PHP haters should read the following.

PHP has conflicting naming of system and library functions. Predictable naming schemes are important in any language.

This is what I love and hate at the same time. However, in its essence this statement is true. Why are some two-word functions separated by underscores and some not? Why does $ needle and $ haystack change places sometimes? This is ridiculous. But in the end, is it really that important? My auto substitution IDE and php.net are always at hand. So perhaps this is a negative factor for PHP as a language. But it doesn’t stop me from being an effective programmer.

PHP developers are constantly abandoning built-in functions and low-level functionality. A good example is the rejection of the possibility of passing parameters to a function by reference. This has become a nightmare for anyone using callbacks, for example.

Personally, I think this is not a good point of view. Such changes are necessary for the evolution of the language, especially for the scale used, like PHP. PHP provides many opportunities to become a bad programmer, but in the same way PHP developers find it difficult to eliminate silly language constructs, such as passing a value by reference. The elimination of this opportunity has become one of the best decisions they have ever made. For a beginner, there is no easier way to shoot one’s leg than to use this “function”.

Lack of logic in redesign. The aforementioned “abbreviations” made it sometimes impossible to specify default values ​​for functions. This bug is fixed in PHP 5, but they also removed the transfer of variables by reference from PHP 4!

I do not think that there is any lack of logic. I think this particular change hurt you a lot and “there was an unpleasant taste in the mouth.” Changes in the language often become known months or even years before their implementation. To go from 4 to 5 there is a migration guide which describes all the differences. Passing parameters by reference was a terrible feature that does not give the developer any advantages that are not achievable by other means.
')
Bad implementation of namespaces (in fact, none at all). And now, when they appeared, what will be used as a separator? Backslash! A symbol that is universally used for escaping, even in PHP!

I have mixed feelings about this. Part of me thinks, “what's the difference, because the escape character makes no sense out of line,” and part of me thinks, “probably, they could have come up with something better.” But could they? I don't know, I'm not a Zend developer. However, the fact that we have no namespaces before 5.3 is a terrible omission.

Excessive use of transform types leads to errors. I have no problem with converting, say, float to int and back. But PHP (when I last checked) will happily try to convert the array to a whole.

I find it normal to disagree with how PHP does this, but I disagree with the fact that it makes the language "bad."

Poor performance with recursion. Recursion is a crucial tool for any language, it can make complex algorithms much easier. Bad support for this is simply unforgivable.

PHP is a DSL for the web. I worked closely with him for 8 years and used recursion on the strength of 4 or 5 times, as a rule, to bypass directories or XML. This is not the approach that is often needed for web development. I do not condone poor performance, but this is a much more academic issue than a productivity issue. If you really need fast recursion, PHP is not your choice.

Functions are case insensitive. I have no idea what they were thinking at that moment when they did it. A programming language is a way to define behavior for both a computer and a programmer, without ambiguity. Case insensitivity introduces many ambiguities.

I agree with this 100%.

PHP encourages (practically requires) the mixing of logic and presentation. Yes, you can write code so that it does not exist, but it really makes it easier to write incorrect (from the point of view of design) code.

How wonderful - people complain about a language that allows them to use any output system (this is clearly indicated by the number and style of template engines for PHP) - OR - skip everything and just output directly. This does not make PHP bad at all. This is part of what makes PHP good.

PHP performance is terrible without caching. Tell me, does anyone sell a commercial caching product for PHP? Oh yeah, PHP developers do it themselves.

Do you mean bytecode caching (for example, accelerators), or output caching?

If the first, then I do not think it is important to me. Accelerators are free and very easy to fasten. We could argue about why they are not part of the language, but in the end, I do not think that this is so important.

If you are talking about output caching, then there is nothing to even talk about. Any web project with significant loads needs to be cached. PHP has nothing to do with it.

In general, I think you consider PHP to be a “bad” language in a very academic sense. And people using PHP code on it “to get things done”.

Source: https://habr.com/ru/post/46783/


All Articles