Laravel 4: Why is my class autoload, but global variables are not available

I loaded the autoload class, which is correctly placed on the names and PSR-0. I put it in app / lib / CI, and the class and its file name are the same "DB". The class file itself contains the configuration file before the actual class:

require( 'config.php' );

class DB {
  // ...
}

The class is explicitly autoloaded because when I call the static connect method, it displays an error message from inside :: connect (). The problem is that global variables that are inside the included config.php are not available inside the class :: method.

So, to be clear, the $ connection_settings array is inside config.php, but even when using:

global $connection_settings;

$ connection_settings is not set inside the connection method.

- , , , route.php, . , , , ""?

+5
1

Composer, Laravel. , ( # 1297). , , , .

PHP :

. , .

( Laravel 4b4 PHP 5.4.13). (-).

config.php

global $connection_settings;
$connection_settings = array(/* ... */);

DB.php

require 'config.php';
class DB {
    static function connect()
    {
        global $connection_settings;
        // Do something with $connection_settings
    }
}
+6

All Articles