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

Closures not working when using the --execute argument. #148

Closed
dmason30 opened this issue Jun 10, 2022 · 1 comment
Closed

Closures not working when using the --execute argument. #148

dmason30 opened this issue Jun 10, 2022 · 1 comment

Comments

@dmason30
Copy link

dmason30 commented Jun 10, 2022

  • Tinker Version: 2.7.2
  • Laravel Version: 9.12.2
  • PHP Version: 8.1

Steps To Reproduce:

Running any one of these commands:

php artisan tinker --execute="optional('foo', fn($v) => dump($v));"
php artisan tinker --execute="transform('foo', fn($v) => dump($v));"
php artisan tinker --execute="tap('foo', fn($v) => dump($v));"
php artisan tinker --execute="with('foo', fn($v) => dump($v));"

php artisan tinker --execute="optional('foo', function ($v) {  dump($v); });"
php artisan tinker --execute="transform('foo', function ($v) {  dump($v); });"
php artisan tinker --execute="tap('foo', function ($v) {  dump($v); });"
php artisan tinker --execute="with('foo', function ($v) {  dump($v); });"

Produces this error

TypeError: Too few arguments to function dump(), 0 passed in /Users/danmason/PhpstormProjects/xxxeval()'d code on line 2 and exactly 1 expected

Running the same functions in PsySh works as expected

$ php artisan tinker
Psy Shell v0.11.2 (PHP 8.1.4 — cli) by Justin Hileman
>>> optional('foo', fn($v) => dump($v));
"foo"
=> "foo"
>>> transform('foo', fn($v) => dump($v));
"foo"
=> "foo"
>>> tap('foo', fn($v) => dump($v));
"foo"
=> "foo"
>>> with('foo', fn($v) => dump($v))
"foo"
=> "foo"
@driesvints
Copy link
Member

You need to escape the $ sign when running this in the CLI:

$ php artisan tinker --execute="optional('foo', fn(\$v) => dump(\$v));" 
"foo"

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

No branches or pull requests

2 participants