CodeIgniter Forums
Why use `global $app` in Toolbar Class? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Why use `global $app` in Toolbar Class? (/showthread.php?tid=82889)



Why use `global $app` in Toolbar Class? - monkenWu - 08-30-2022

Hi, I found the "global $app;" used in the prepare method of the "CodeIgniter\Debug\Toolbar" Class.


In the new version of CodeIgniter4 we can use "\Config\Services::codeigniter()" to get the shared CodeIgniter entity. So I'm not sure if using "global $app;" is needed.

Since I am doing some work for CodeIgniter4 to support high performance servers (RoadRunner & WorkerMan), so "global $app;" is a problem that bothers me.


RE: Why use `global $app` in Toolbar Class? - kenjis - 08-30-2022

Probably just because the code was written before Services::codeigniter() was added.


RE: Why use `global $app` in Toolbar Class? - ping-yee - 08-31-2022

We changed  "global $app;" to "$app = \Config\Services::codeigniter();" and run unit test below of "tests/system/Debug/" folder, It looks like doesn't have any problem.
Does this change need to be modified at next version?


RE: Why use `global $app` in Toolbar Class? - kenjis - 09-12-2022

This was fixed in develop, and will be fixed in v4.2.7.
See https://github.com/codeigniter4/CodeIgniter4/pull/6524