Laravel Error: Call to undefined function

28 views Asked by At

I have defined a debug_to_console function in the public/index.php file in the global namespace

I am trying to access this function inside the App\Providers\AppServiceProvider class in the boot() method

When I try to start my Laravel application using "php artisan serve" command I get the following error

Call to undefined function debug_to_console()

at app\Providers\AppServiceProvider.php:22 18▕ * Bootstrap any application services. 19▕ */ 20▕ public function boot(): void 21▕ { ➜ 22▕ \debug_to_console("Foo"); 23▕ } 24▕ 25▕ }

1 vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36 App\Providers\AppServiceProvider::boot()

2 vendor\laravel\framework\src\Illuminate\Container\Util.php:41 Illuminate\Container\BoundMethod::Illuminate\Container{closure}()

When I remove the function call and start the app then rewrite the function call while the server is working it works fine which means if the server was running the code works with the function call

Also when I call the function from a controller method it works

What is the cause of this error and how can I avoid it ?

0

There are 0 answers