An interview question about include in php? Can the following code be executed normally? If there is any problem? PHPcodeif ($ condiation) include (. php); elserequire_once (B. php); do not know how to answer ------ solution ------------------ include () will generate a warning, and require (a question about the include of php?
Can the following code be executed normally? If there is any problem?
PHP code
if($condiation) include('a.php'); else require_once('b.php');
Do not know how to answer
------ Solution --------------------
Include () generates a warning, while require () causes a fatal error (an error occurs, the script stops executing) ++
------ Solution --------------------
If the include and include_once requests do not reach the file, the system reports the warning message.
The program will continue to run
It can be used in ifelse statements.
Different from require and require_once, if the file cannot be requested, a fatal error will occur and the script is terminated.
Whether require_once or require can obtain the execution permission, the code lines with require and require_once will be executed. this is related to the PHP execution mechanism.
So the above code can be executed. the result of execution is
If the condition is true,. php and B. php will not report errors. if. php but no B. php reports a fatal error. if the request is sent to B. php does not request. php reports a warning. if both files do not exist. A warning and fatal error will be reported.
If the conditions are not true
The effect is similar, but there is no warning.