Composer autoload returns Undefined variable

Hi, I have a problem with the composer when I automatically download the configuration file.

In my composer.json I create

{
"require": {"monolog/monolog": "1.7.*@dev"},
"autoload":{
    "files": ["config/application.config.php"]
    }
}

I want to autoload my configuration file, and in my test.php file I will put:

// Get composer autoloading
require 'vendor/autoload.php';


use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\FirePHPHandler;

$logger = new Logger('my_logger');
$logger->pushHandler(new StreamHandler(__DIR__.'/data/logs/log.log', Logger::DEBUG));
$logger->pushHandler(new FirePHPHandler());

$logger->addInfo('test message');

// test
echo $config['logs_dir'];

My application.config.php file contains

/*
 * Data paths
 */
$config['cache_dir'] = 'data/cache';
$config['logs_dir']  = 'data/logs';

I get a notification when I try to print a value in my call to test.php echo $ config ['logs_dir']. The file was uploaded successfully by the composer, but notice that I get

Note: Undefined variable: $ config in D: \ xampp \ htdocs \ MCF3 \ index.php on line 18

+4
source share
1 answer

Composer require, , :

$config['cache_dir'] = 'data/cache';

. / , $GLOBALS.

$GLOBALS['config']['cache_dir'] = 'data/cache';
+6

Source: https://habr.com/ru/post/1523559/


All Articles