PHP introduces the return value of include

Source: Internet
Author: User

Original link: https://my.oschina.net/banbo/blog/299370

PHP has an include, as its name implies, is used to include files. The corresponding require, as well as two with once. I wonder if you have noticed the return value of the include. Typically, contains a successful return of 1, including failure to return false. However, if the included file is returned with return, then the value is the value of returns. Like what:

1.php

<?php
$ret = include ' 2.php ';
Echo $ret; Output Wakaka
?>

2.php

<?php return
' Wakaka ';
? >


You can see from the 1.php output that the return value of the include is the ' Wakaka ' in 2.php.


What is the use of this feature? I use it to conveniently use PHP files for configuration. For example, a configuration file can be written like this:

config.php

<?php return
Array ('
db ' =>array ('
host ' => ' localhost ',
' user  ' => ' root ',
' password ' => ' Wakaka ',
' name ' => ' Test ',
' encoding ' => ' UTF8 '
)
);
? >


When loading, only need $conf = include ' config.php '; This is how the thinkphp configuration file is returned.

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.