An interview question about include in php? How to deal with it-php Tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.