Because in addition to PHP7, the remaining versions do not support define an array, if a site global configuration of the array file, such as database account password, page number, routing rules easy to save into an array file, put into the config.php, the global use of this file is included, only need to use the $ Config, will this increase server memory consumption?
Reply content:
Because in addition to PHP7, the remaining versions do not support define an array, if a site global configuration of the array file, such as database account password, page number, routing rules easy to save into an array file, put into the config.php, the global use of this file is included, only need to use the $ Config, will this increase server memory consumption?
Theoretically, this is equivalent to Requrie ' config.php ', but consumption can be negligible.
Can ignore ...
First you should be clear that whether you define a constant array or an ordinary array, it is memory-intensive.
If you don't want to be modified after the definition, use a constant array:
如果你在定义后需要修改,那就用普通数组,比如在需要时才生成数据库连接对象:
'db_conn_obj');function we_db(&$app) { $app['db'] = @new mysqli('127.0.0.1', 'root', 'pass', 'mysql'); register_shutdown_function(function() use ($app) { $app['db']->close(); });}function we_foo1() { global $app; if(!is_object($app['db'])) we_db($app); return $app['db']->query('select user,host from user where user = \'root\'')->fetch_all();}function we_foo2() { global $app; if(!is_object($app['db'])) we_db($app); return $app['db']->query('select user,host from user')->fetch_all();}print_r(we_foo1());print_r(we_foo2());
Since there are more things, the memory consumption will inevitably increase. But unless you configure the item to be perverted, you can generally ignore the
//from php5.6 after const can define an array, and define () began to support const FOO after php7.0 = [ [Efine];d (' FOO ');