vendredi 28 juin 2019

ErrorException Undefined variable After moving to laravel helper functions

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.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FHGtjI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire