Slim/Twig Application Error only on remote server

When I run a local server my website is working fine with Slim. I did not change any vendor code.

But when I upload my project to a remote server and try to run it there, it throws the error below. I don’t understand, because I didn’t change any vendor code so it can’t be that there’s anything wrong with that. The error occurs with the following function in Twig.php. But both of the arguments have a default value of empty array.

public function fetch($template, $data = [])
{
    $data = array_merge($this->defaultVariables, $data);

    return $this->environment->render($template, $data);
}

Slim Application Error

The application could not run because of the following error:

Details

Type: TypeError

Message: Argument 2 passed to Twig\Environment::render() must be of the type array, null given, called in /vendor/slim/twig-view/src/Twig.php on line 92

File: /vendor/twig/twig/src/Environment.php

Line: 316

problem here is that you are passing NULL somewhere in your (probably) “controller” (anonymous function)

  • Twig->render(Object(Slim\Http\Response), ‘index.html.twig’, NULL)

(passing null to array_merge should produce at least PHP Warning, that means you have disabled php error reporting)

problem is in your controller and disabled error reporting (error might change value of variable to null)

Yes I know NULL was passed somewhere, but the problem is I don’t know where or how. Because on my local php server, I use the exact same routing and controllers, but I don’t have any problem there.

Edit. Fixed through error reporting. It happened to be a JSON file that had a bad route that could not be found. Thanks!