Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument #1 ($function) must be of type Closure|string, array give #1652

Closed
francoism90 opened this issue Jan 7, 2025 · 11 comments
Closed
Labels

Comments

@francoism90
Copy link

Versions:

  • ide-helper Version: 3.5.2
  • Laravel Version: 11.37.0
  • PHP Version: 8.4.2

Description:

sail a ide-helper:generate

   TypeError 

  ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given

  at vendor/barryvdh/laravel-ide-helper/src/Alias.php:454
    450▕         if (is_object($macro_func) && is_callable($macro_func) && !$macro_func instanceof Closure) {
    451▕             return new \ReflectionMethod($macro_func, '__invoke');
    452▕         }
    453▕ 
  ➜ 454▕         return new \ReflectionFunction($macro_func);
    455▕     }
    456▕ 
    457▕     /*
    458▕      * Get the docblock for this alias

      +28 vendor frames 

  29  artisan:13
      Illuminate\Foundation\Application::handleCommand()

Steps To Reproduce:

  • Upgrade to latest version
  • Run php artisan ide-helper:generate
  • Get this error

If you need more info, please let me know!

@francoism90 francoism90 added the bug label Jan 7, 2025
@ziming
Copy link

ziming commented Jan 7, 2025

yup, getting this too

@barryvdh
Copy link
Owner

barryvdh commented Jan 7, 2025

Can you dump what is in the array there?

@dualznz
Copy link

dualznz commented Jan 7, 2025

Method Jenssegers\Agent\Facades\Agent::handle() does not exist
Context:

{
  "exception": "[object] (ReflectionException(code: 0): Method Jenssegers\\Agent\\Facades\\Agent::handle() does not exist at /home/vagrant/code/paVMS/vendor/barryvdh/laravel-ide-helper/php-templates/middleware.php:41)
[stacktrace]
#0 /home/vagrant/code/paVMS/vendor/barryvdh/laravel-ide-helper/php-templates/middleware.php(41): ReflectionClass->getMethod()
#1 [internal function]: Illuminate\\Filesystem\\Filesystem::{closure}()
#2 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(609): array_map()
#3 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(795): Illuminate\\Support\\Arr::map()
#4 /home/vagrant/code/paVMS/vendor/barryvdh/laravel-ide-helper/php-templates/middleware.php(5): Illuminate\\Support\\Collection->map()
#5 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(148): require_once('...')
#6 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(149): Illuminate\\Filesystem\\Filesystem::Illuminate\\Filesystem\\{closure}()
#7 /home/vagrant/code/paVMS/vendor/barryvdh/laravel-ide-helper/src/Console/MetaCommand.php(311): Illuminate\\Filesystem\\Filesystem->requireOnce()
#8 /home/vagrant/code/paVMS/vendor/barryvdh/laravel-ide-helper/src/Console/MetaCommand.php(207): Barryvdh\\LaravelIdeHelper\\Console\\MetaCommand->loadTemplate()
#9 /home/vagrant/code/paVMS/vendor/barryvdh/laravel-ide-helper/src/Console/MetaCommand.php(155): Barryvdh\\LaravelIdeHelper\\Console\\MetaCommand->getExpectedArgumentSets()
#10 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Barryvdh\\LaravelIdeHelper\\Console\\MetaCommand->handle()
#11 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#12 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure()
#13 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#14 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Container/Container.php(694): Illuminate\\Container\\BoundMethod::call()
#15 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\\Container\\Container->call()
#16 /home/vagrant/code/paVMS/vendor/symfony/console/Command/Command.php(279): Illuminate\\Console\\Command->execute()
#17 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\\Component\\Console\\Command\\Command->run()
#18 /home/vagrant/code/paVMS/vendor/symfony/console/Application.php(1094): Illuminate\\Console\\Command->run()
#19 /home/vagrant/code/paVMS/vendor/symfony/console/Application.php(342): Symfony\\Component\\Console\\Application->doRunCommand()
#20 /home/vagrant/code/paVMS/vendor/symfony/console/Application.php(193): Symfony\\Component\\Console\\Application->doRun()
#21 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(198): Symfony\\Component\\Console\\Application->run()
#22 /home/vagrant/code/paVMS/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1205): Illuminate\\Foundation\\Console\\Kernel->handle()
#23 /home/vagrant/code/paVMS/artisan(13): Illuminate\\Foundation\\Application->handleCommand()
#24 {main}
"
}

&&

php artisan ide-helper:meta

   ReflectionException

  Method Jenssegers\Agent\Facades\Agent::handle() does not exist

  at vendor/barryvdh/laravel-ide-helper/php-templates/middleware.php:41
     37▕             return $result;
     38▕         }
     39▕
     40▕         $reflected = new ReflectionClass($middleware);
  ➜  41▕         $reflectedMethod = $reflected->getMethod('handle');
     42▕
     43▕         $result = array_merge($result, [
     44▕             'class' => $middleware,
     45▕             'uri' => $reflected->getFileName(),

      +1 vendor frames

  2   [internal]:0
      Illuminate\Filesystem\Filesystem::{closure}()
      +21 vendor frames

  24  artisan:13
      Illuminate\Foundation\Application::handleCommand()

getting same isdue on php artisan ide-helper:meta

@dualznz
Copy link

dualznz commented Jan 7, 2025

i fixed mine it was the package i was using

@mihob
Copy link

mihob commented Jan 7, 2025

same problem here

@dualznz
Copy link

dualznz commented Jan 8, 2025

im not seeing this issue, im also not using sail but i might setup a testbed to see if i can reproduce it.

@barryvdh
Copy link
Owner

barryvdh commented Jan 8, 2025

i fixed mine it was the package i was using

What package?

I'll catch the errors in #1654 now but would be better to fix.

@barryvdh
Copy link
Owner

barryvdh commented Jan 8, 2025

What macros do you have defined?

@barryvdh
Copy link
Owner

barryvdh commented Jan 8, 2025

This issue should be fixed with #1655

@francoism90
Copy link
Author

@barryvdh This the args:

array:1 [▼
  "exception" => Error {#25436 ▼
    #message: "Call to undefined method Spatie\CollectionMacros\Macros\At::slice()"
    #code: 0
    #file: "
/var/www/html/vendor
/spatie/laravel-collection-macros/
src/Macros/At.php"
    #line: 28
    trace: {▶}
  }
]

@francoism90
Copy link
Author

@barryvdh Closing this as v3.5.3 fixes this issue.

Thanks for the quick fix. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants