fs_tigre fs_tigre - 6 months ago 10
PHP Question

Is it common to have just a return statement in a php file - PHP

Sorry about the simple question but I'm fairly new to PHP.

Is it common to have just a return statement in a php file? If yes, can someone show me how this is used in other files?

<?php

return ['someVariable' => 'someValue'];


A perfect example is the config files in the Laravel framework, for instance the database.php.

Thanks

Answer
//config.php
<?php
    return [
        'app_key' => 'SomeRandomString',
        'app_secret' => 'SomeRandomString',
    ]; 

-

// other-file.php
<?php
    $config = require('path/to/config.php');
    $facebook = new Facebook($config['app_key'], $config['app_secret']);