Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Statement Explanation

Tags:

php

I read a post here that the person wrote a statement like :

 $this->_connection = require_once 'config.php';

   // $this->connection is an array variable.

I find it a little bit hard to understand. Am asking myself how can you assign an included file to a variable.

Does it mean that an array must be returned from the "config.php" file? I mean should "config.php" return an array?

Is such statement good in commercial php applications?

Thank you.

like image 486
Marko Morris Avatar asked Dec 29 '12 21:12

Marko Morris


1 Answers

The included file may have a return statement outside of any function. If this happens, the script stops running the included file and the "return value" of the require_once call is the value of the return statement.

Docs

like image 102
Niet the Dark Absol Avatar answered Oct 02 '22 01:10

Niet the Dark Absol