I'm in the process of moving a PHP project from a spaghetti mess to Laravel. And by Spaghetti I really mean it. The code does not use classes and the PHP files are a mix of HTML and PHP with functions. So far, due to the project being made in PHP 7.1, I cannot use any newer version of Laravel other than 5.8. My initial plan is to get this working alongside Laravel but as-is and only use the Laravel functionality that is required for now (e.g. disabling CSRF check on post forms and adding all endpoints as single routes). Recoding it all from scratch is not possible.
So far I've configured and setup a Laravel Homestead and moved all the projects files into the public folder. I'm facing some issues with global vars inside functions. Theres a lot of functions all around the project php files that uses this to connect to the db like so:
function do_something() {
global $connectionVar
...
}
The problem is that the $connectionVar is null. Its defined in a config file that is included in all the PHP files like so $connectionVar = mysqli(...);, but I think that where this $connectionVar is defined is no longer considered as being global as it is now run inside laravel.
Can I somehow and/or somewhere define this $connectionVar so that it can be used like in the above function without me having to change every single function that uses it?
I've planned to change this to use eloquent at a later point, but right now I want to make it work as it is now with as little influence from Laravel as possible, and then slowly migrate everything piece by piece.