About php script execution

When establishing a file info.php test, test some php method syntax error is found nothing suggesting, directly reported to the 500 error page
Insert picture description here
set upini_set(‘display_errors’,‘On’); error_reporting(E_ALL | E_STRICT);After that, it doesn't work and there is no error message.
Modify these two configurations directly in the php.ini configuration file, and the result shows an error message.

Why doesn't dynamic configuration work? Could it be that dynamic settings didn't work? After restoring php.ini to its original state, the wrong syntax is deleted in info.php, the code is as follows

<?php
	ini_set('display_errors','On');
	error_reporting(E_ALL | E_STRICT);
	phpinfo();

The phpinfo information is
Insert picture description here
printed. From the printed content, it shows that the dynamic configuration has taken effect, but why can't it show the syntax error of the code?
Because the execution mechanism of the php file is ignored
PHP is a scripting language. A series of compilation processes are required to execute code before it can be executed. In the file compilation stage, the code syntax is verified, but the code is not executed at this time, so the dynamic configuration at the beginning of the file is meaningless. Syntax error was judged when compiling, and the script stopped running. The default configuration is directly called, and no error message is displayed. This is why the configuration in php.ini can take effect, but the dynamic configuration is invalid.

Let's create a new file error.php at this time

<?php
	$a = 'dd'
	echo $a

Modify the info.php file

<?php
	ini_set('display_errors','On');
	error_reporting(E_ALL | E_STRICT);

	include('./error.php');

After we executed the info.php file, an error message appeared smoothly at this time.

Because there is no syntax error in the info.php file at this time, the script starts to execute smoothly. The dynamic configuration is executed first and it takes effect, and then the operation of importing the error.php file is executed. After the error.php file is imported, the verification and compilation operations of the file are started, and it is found that the file has a syntax error. According to the configuration that has taken effect, an error message will be thrown.

Insert picture description here

Summary: I didn't notice this problem before, because during the development process, these dynamic configurations usually appear in the entry file or configuration file, rarely in the same file as the error code, and the dynamic configuration is not affected by the error code.

Guess you like

Origin blog.csdn.net/u012830303/article/details/94570151