PHP return usage

Source: Internet
Author: User
The use of the CI framework in PHP's return usage is studied today. I noticed that his configuration file adopts a method. As follows:

/**
* Comments
* The following is a file in the format of config. php.
*/
Return array (
'Config1' => 'some value ',
'Config2' => 'some value ',
);
?>

In this file, a return is directly written, and this usage breaks through my common sense again. Specifically, I queried the document, which is described as follows:
Return
If called from within a function, the return () statement immediately ends execution of the current function, and returns its argument as the value of the function call. return () will also end the execution of an eval () statement or script file.
If called from the global scope, then execution of the current script file is ended. if the current script file was include () ed or require () ed, then control is passed back to the calling file. furthermore, if the current script file was include () ed, then the value given to return () will be returned as the value of the include () call. if return () is called from within the main script file, then script execution ends. if the current script file was named by the auto_prepend_file or auto_append_file configuration options in php. ini, then that script file's execution is ended.
The return statement can terminate the execution of the function. here we also mention that the eval process can be terminated. if it is in an include file, it also makes the return value of the include and require functions. The advantage of writing this is that a statement can get the configuration item content.

// The original write
Require './config. php ';
Function test (){
Global $ config;
If ($ config ['A'] = 'B') echo 'hello ';
}

// Now
Function test (){
$ Config = require ('./config. php ');
If ($ config ['A'] = 'B') echo 'hello ';
}
?>

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.