Why do many programmers consider PHP a bad language? – experts answer

Why do many programmers consider PHP a bad programming language? This is mainly due to the ambiguity that is present when writing programs in this language. On the Internet, I found the following code:

$ arg = 'T';
$ vehicle = (($ arg == 'B')? 'bus':
($ arg == 'A')? 'airplane':
($ arg == 'T')? 'train':
($ arg == 'C')? 'car':
($ arg == 'H')? 'horse':
echo $ vehicle;

What do you think he will print? In languages ​​such as Java, C ++, or C #, there is a similar conditional expression operator. There he will type ‘train’. And in PHP, the result is ‘horse’!

The second point that causes difficulties with PHP is the error diagnosis. If you open a file, then there is a function fopen (). If it is not possible to open the file, an error message will be output to the stream. We can suppress it using the symbol @, i.e. write down @fopen (). However, even with this operator, if you specified the option in the php.ini settings scream.enabled = true, this will print an error message even if you use the operator in the code @.

The third point is related to the ambiguity of the operator ==. Here on this resource there is a good table, what results it returns.

The whole problem is that this operator "does not find fault" with data types. So an expression of the form 123 == "123foo" will return TRUE, and here is the expression "123" == "123foo" will return False. This operator tries to do a type conversion and in the first expression simply converts the string “123foo” to number 123, when in other programming languages ​​we would get an error, which is logical. And the second expression simply compares the strings. All this creates ambiguity, which is very difficult for beginner PHP programmers to cope with. A good programming language should not leave room for the interpretation of certain constructions, but should be consistent everywhere and always.

And the fourth point why they consider this programming language to be bad is the moment that it was created as a template language that is embedded in HTML code using tags . As a result, this led to a mixture of program code and data, which is unacceptable in large systems. It is clear that then came the "best practices" of how to write and how not to write PHP scripts, but for beginner developers this still poses a certain complexity.

In defense of the programming language PHP, I want to say that in its own way it is a powerful programming language that has found its place in web applications. A lot of web applications are written on it, starting from Facebook and ending with the Majoromo smart home system, CMS Drupal and others.

Similar Posts

Leave a Reply