1
votes

I've got an old website which once was in vanilla php. I migrated to laravel putting the whole code under a 'legacy-folder' in views and I had a folder with a lot of functions in it.

Everything was running fine at this point.

In order to go one step further I moved the functions from the folder inside views into helpers. Now I get a few type of errors repeated everywhere in the codebase, I'm debugging them but they are a lot and I don't know why they are thrown now and not before.

For example errors are now thrown if:

  • undefined index of an array is accessed

    $a = $_GET['a'];

  • undefined property of object is accessed

    $a = $b->c;

  • I try to enqueue an unset variable to itself

    $a .= " example";

  • foreach on unset variable is called

  • function is passed an unset variabile

This is my routes/web.php

Route::get('{path?}', 'LegacyPagesController@show')->where('path', '.+');
Route::post('{path?}', 'LegacyPagesController@show')->where('path', '.+');

LegacyPagesController

public function show($path='index.php')
{
  ob_start();
  require(base_path('resources/views/legacy-pages/').$path);
  return ob_get_clean();
}

I've put the helpers in App\Helpers\ExampleHelper.php as classless collection of functions and in composer.json

"autoload": {
    "files": [
        "app/Helpers/ExampleHelper.php",

I'm not sure if these errors are related to the new helpers or a mistake in my routing or if anything else might be involved like php version or php.ini configuration. Any suggestion is appreciated.

1
What version of PHP and Laravel are you using? I'm guessing when you moved to laravel it required a higher version of PHP that now throw errors instead of warnings for those things.N Mahurin
I moved to laravel and upgraded to php 7 in different moments and everything was working. Right now I only moved the helpers function but a lot of time have passed and there might be some changes on the web server I'm not aware of. Anyway laravel 5.2 and php 7.2Riccardo
It sounds like your php error reporting settings was changes to show notices. Else it could be your env has debug enabled.Oliver Nybroe
They are not just showing, they are blocking execution. Can notices do this? Debug is indeed enabled because it's my testing environment as it was before these changesRiccardo
Should only block if strict is enabled.Oliver Nybroe

1 Answers

1
votes

To remove the error message you see, just change your error_reporting variable like so:

ini_set('error_reporting', E_ALL & ~E_STRICT);

It is recommended to have it on and instead fix the errors, as it is indeed errors, php is just smart enough to handle them for you. This answer shows the recommended settings from the php team.