Argument #1 ($callback) must be of type Closure, array given

519 Views Asked by At

U am running a driving school system on PHP/Apache and I am getting this error when I am trying to load the system.

Errors appear to be from routes.php and SimpleRouter.php. Here is the error:

Fatal error: Uncaught TypeError: Pecee\SimpleRouter\SimpleRouter::group(): Argument #1 ($callback) must be of type Closure, array given, called in C:\xampp\htdocs\driving\src\routes.php on line 17 and defined in C:\xampp\htdocs\driving\vendor\pecee\simple-router\src\Pecee\SimpleRouter\SimpleRouter.php:182 Stack trace: #0 C:\xampp\htdocs\driving\src\routes.php(17): Pecee\SimpleRouter\SimpleRouter::group(Array, Object(Closure)) #1 C:\xampp\htdocs\driving\src\Application.php(94): require_once('C:\xampp\htdocs...') #2 C:\xampp\htdocs\driving\index.php(11): Simcify\Application->route() #3 {main} thrown in C:\xampp\htdocs\driving\vendor\pecee\simple-router\src\Pecee\SimpleRouter\SimpleRouter.php on line 182

**Code snippet for routes.php line 17: **

Router::group(['prefix' => '/driving'], function()
 {    
      Router::group(array(
        'exceptionHandler' => Handler::class
    ), function()
     {
        Router::group(array(
            'middleware' => Simcify\Middleware\Authenticate::class
        )

Code snippet for simpleRouter.php line 182:

  public static function group(\Closure $callback, array $settings = [])
    {
        if (is_callable($callback) === false) {
            throw new InvalidArgumentException('Invalid callback provided. Only functions or methods supported');
        }

Please assist. Thanks in advance

1

There are 1 best solutions below

7
volkerschulz On

It seems to me as someone has tampered with SimpleRouter.php. The functions signature is (and always has been) public static function group(array $settings, Closure $callback): IGroupRoute and not vice versa.

Since it is inside the vendor folder, I suppose it was installed via composer? Make a backup and then try composer update for starters. If this doesn't work, add your composer.json to your question.

This is the source repository: https://github.com/skipperbent/simple-php-router/tree/master