In defense of PHP

Original author: BaileyP
  • Transfer
Recently, a topic was created on stackoverflow in which the author claimed that PHP was a non-important language and asked to convince him. As arguments, he cited several arguments that were sequentially commented on by another participant. A free translation of this is presented below.
Personally, I completely agree with the responder and I think that all PHP haters should familiarize themselves with the following.

PHP имеет противоречивое именование системных и библиотечных функций. Предсказуемые схемы именования имеют важное значение в любом языке.

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

PHP разработчики постоянно отказываются от встроенных функций и низкоуровневой функциональности. Наглядным примером является отказ от возможности передачи в функцию параметров по ссылке. Это стало кошмаром для всех, кто использует, например, обратные вызовы.

Personally, I think this is not a very good point. Such changes are necessary for the evolution of the language, especially for a large-scale one, like PHP. PHP provides a lot of opportunities to become a poor programmer, but in the same way, PHP developers find it difficult to eliminate stupid language constructs, such as passing a value by reference. Eliminating this opportunity has become one of the best decisions they have ever made. For a beginner, there is no simpler way to shoot yourself in the foot than using this “function."

Отсутствие логики при редизайне. Вышеупомянутые «сокращения» сделали иногда невозможным указывать для функций значения по умолчанию. Этот баг пофиксен в PHP 5, но они же убрали передачу переменных по ссылке из PHP 4!

I do not think that there is any flaw in the logic. I think that this particular change strongly affected you and "there was an unpleasant aftertaste in your 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 that describes all the differences. Passing parameters by reference was a terrible trait that did not give the developer any advantages that could not be achieved in other ways.

Плохая реализация нэймспейсов (фактически из вообще нет). А сейчас, когда они появились, что будет использоваться в качестве разделителя? Бэкслэш! Символ, который повсеместно используется для экранирования, даже в PHP!

I have mixed feelings about this. Part of me thinks, “what's the difference, because the escape character does not make sense outside the line”, and part of me thinks “they probably 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.

Чрезмерное применение пребразования типов приводит к ошибкам. У меня нет проблем с преобразованием, скажем, float в int и обратно. Но PHP (когда я последний раз проверял) с радостью попробует преобразовать массив в целое.

I think it’s normal to disagree with how PHP does this, but I don’t agree that it makes the language “bad”.

Плохая производительность при рекурсии. Рекурсия является принципиально важным инструментом для любого языка, она может делать сложные алгоритмы намного проще. Плохая поддержка этого просто непростительна.

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, usually to bypass directories or XML. This is not the approach often needed for web development. I do not condone low productivity, but this is a much more academic issue than productivity. If you really need fast recursion, PHP is not your choice.

Функции нечувствительны к регистру. Я понятия не имею, о чём они думали в тот момент когда сделали это. Язык программирования это способ определить поведение как для компьютера, так для программиста, без двусмысленности. Нечувствительность к регистру вводит много неясностей.

I 100% agree with that.

PHP поощряет (практически требует) смешивание логики и представления. Да, вы можете написать код так, чтобы этого не было, но он действительно упрощает написание неправильного (с точки зрения проектирования) кода.

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

Производительность PHP ужасна без кэширования. Скажите, кто-нибудь продаёт коммерческий продукт кэширования для PHP? Ах да, это делают сами разработчики PHP.

Do you mean bytecode caching (e.g. 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 this is so important.

If you are talking about output caching, then there’s nothing to even talk about. Any web project with significant workloads needs caching. PHP has nothing to do with it.

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