This is historical legacy code. The original programmer directly instantiated the database instance in the configuration file
$db = new db();
If this kind of code is normally included using require/include, there will be no problem. When it is judged, $GLOBALS['db'] is used to judge.
Because there are a lot of files, I want to reuse some of the models. Because of the inclusion relationship, I have to try them one by one and then include them. I want to make them load automatically, so I used composer to automatically load the files. $GLOBALS['db'] is empty. I usually don't use this global parameter, so I don't know what the situation is.
I have solved this problem myself, just change $db = new db() to $GLOBALS['db'], that is, assign the value explicitly.
I don’t understand why $db that is included manually will exist, but $db that is automatically loaded using composer will disappear. Please give me some guidance.
This is historical legacy code. The original programmer directly instantiated the database instance in the configuration file
$db = new db();
If this kind of code is normally included using require/include, there will be no problem. When it is judged, $GLOBALS['db'] is used to judge.
Because there are a lot of files, I want to reuse some of the models. Because of the inclusion relationship, I have to try them one by one and then include them. I want to make them load automatically, so I used composer to automatically load the files. $GLOBALS['db'] is empty. I usually don't use this global parameter, so I don't know what the situation is.
I have solved this problem myself, just change $db = new db() to $GLOBALS['db'], that is, assign the value explicitly.
I don’t understand why $db that is included manually will exist, but $db that is automatically loaded using composer will disappear. Please give me some guidance.