Home > Software design >  Laravel log changes without action, helpers.php issue
Laravel log changes without action, helpers.php issue

Time:10-11

During the development, I opened website logs and found a large number of errors with the same text:

local.ERROR: Cannot redeclare fun() (previously declared in C:\laragon\www\am\bootstrap\helpers.php:10) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Cannot redeclare errorText() (previously declared in C:\\laragon\\www\\am\\bootstrap\\helpers.php:10) at C:\\laragon\\www\\am\\app\\helpers.php:10)

At first I thought that these errors occur in parallel with my action on local website, but it turned out that these errors appear every 1 minute in the logs. I do not understand what provokes them. There are no such errors in the browser during operation, even if the website without action for several hours, logs still fill every minute.

I learned everything I could about the help file. The only option is to check if the function exists, but this is not the best practice, especially since the site works and does not give any errors in the process.

Fucntion check example:

if (! function_exists('fun')) {
function fun($field) {
    return view('static.error', ['field' => $field]);
}

}

But rewriting and wrapping dozens of functions is not a good idea. Moreover, the problem remains and it is still not clear to me where and how these errors appear, what provokes them? Additionally considering that I have a static php website.

CodePudding user response:

I will try to explain everything in the simplest possible language. A long search for an answer led me to the obvious thing. The whole problem is solved by creating a file inside bootstrap laravel directory. I trusted the opinion of the weighty answers here, but they are no longer relevant for today's queries.

It is also very important not to leave helpers.php inside app directory, even if it is not connected anywhere. This is what caused constant log entries.

All this will avoid duplication errors of any type and and will be compliant.

  • Related