Home  >  Article  >  Backend Development  >  Two big pitfalls caused by upgrading Php 7.4

Two big pitfalls caused by upgrading Php 7.4

藏色散人
藏色散人forward
2020-02-08 13:07:145388browse

Since my machine uses the rolling update of Archlinux, Php has been upgraded to 7.4 without knowing it. I didn't expect that this update would cause great trouble. First, the new option ProtectHome of Php-fpm will cause the classic File not found error, and then the Php interpreter will directly report an error Trying to access array offset on value of type null for subscript access of null type.

Recently I was helping a friend build a website, so I pulled the online code back to the local mirror for testing. Because the web application has some strange dependencies, in order not to pollute the local environment, I deployed it in Docker for testing. Docker's basic image chooses the radical Archlinux, paired with Php7.4, which was released at the end of last month. So I spent a whole afternoon stuck in the Debug pit...

First of all, after setting up the environment with a shuttle, I ran it and reported one of the most classic and most pitiful errors in Php-fpm: File not found. Anyone who has configured Php-fpm knows that this error is usually caused by incorrect file permissions or incorrect file paths, and both of these errors are relatively difficult to find. So I once again experienced the path inspection with big eyes and small eyes, and there was no problem. File permission check, emmm, is there no problem? I went back and checked the path, and it was still OK! I was so frustrated that chmod 777 failed to solve the problem. I was a little doubtful about my life...

I searched online for the File not found error of Php-fpm. Although there were many results, there were only these two reasons. And these two reasons were eliminated one by one, and things suddenly developed from a magical angle...

I don’t know how long it took me to think that it might be related to the Php version (because my local computer I also ran other Php applications, so I didn’t think there was a problem with Php at first). So I searched for the changes in the new version of Php7.4 and Php-fpm7.4, and immediately found the culprit:

Php7.4 Commit

(https:// github.com/php/php-src/commit/40c4d7f1820df1872a71ab07fd26da45a203e37f#diff-c0605c0e7e1db864472acf66a9812d33R22)

An option has been added to this commit: ProtectHome. As the name suggests, when turned on, PHP will not execute files in the home directory - and the default value of this new option happens to be turned on. Use systemctl edit php-fpm.service to add an option override. After restarting the service, everything is finally normal, and the second big error comes:

Inlcude, require, etc. are often used in Php to include other files. The debugging found that after a certain include, PHP stopped execution directly and reported an error Trying to access array offset on value of type null. But the online code ran without any problems, which was very strange. After following the include file, I found that there was a place where the array elements were accessed, but the array itself was null. This syntax is generally supported in weakly typed languages ​​like Php. It will return null as a whole, but in the new version of Php7.4, this syntax will be reported as an error. It seems that Php is also standardizing the characteristics of the language a little bit. There is no way, I can only change the code myself. (Although I currently choose to use the old version of Php)

Since Php7.4 was released not long ago, it is estimated that it has not been widely updated and used, and the developers of various applications may not have tested Php7.4. and compatible modifications. It is precisely for this reason that when searching for this information on the Internet, I could not find any valuable suggestions. In addition to recording the whole afternoon of being fooled by this new feature, this article also provides other people with an idea for solving similar problems. Bar.

The above is the detailed content of Two big pitfalls caused by upgrading Php 7.4. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:sbw.so. If there is any infringement, please contact admin@php.cn delete