简体   繁体   中英

why require_once just return true, not the array I define;

I was require a file just define a array. like:

$config = require_once base_path().'/config/webchat.php';
var_dump($config);
exit();

and the webchat.php is just define a array like :

$path = __DIR__.'/../storage/webchat_tmp/';

return [
    'path'     => $path,
    /*
     * swoole 配置项(执行主动发消息命令必须要开启)
     */
    'swoole'  => [
        'status' => false,
        'ip'     => '127.0.0.1',
        'port'   => '8866',
    ]
];

the $config was result in a boolean true, not the array. could someone tell me why , thanks a lot . and the path is right. because when I set exit() in the webchat.php . it was exit right;

require_once return true if file successfully included. But it doesn't return array. So you should write following code to have $config array in other file. In the other words you add lines of webchat.php in other file by require_once it:

require_once base_path().'/config/webchat.php';
var_dump($config);
exit();

And

$path = __DIR__.'/../storage/webchat_tmp/';

$config = [
    'path'     => $path,
    /*
     * swoole 配置项(执行主动发消息命令必须要开启)
     */
    'swoole'  => [
        'status' => false,
        'ip'     => '127.0.0.1',
        'port'   => '8866',
    ]
];

When execute the php code, it seems like this:

$path = __DIR__.'/../storage/webchat_tmp/';

$config = [
    'path'     => $path,
    /*
     * swoole 配置项(执行主动发消息命令必须要开启)
     */
    'swoole'  => [
        'status' => false,
        'ip'     => '127.0.0.1',
        'port'   => '8866',
    ]
];

var_dump($config);
exit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM