Closed eldair closed 3 months ago
I can't reproduce it. What version of laravel? If you hover over app()
what signature does it show? Are there multiple signatures?
Hi @bmewburn , it's Laravel v11.0.8 and it happens in any file with that call. There is only a single signature
@bmewburn Whoops I missed this and duplicated the same issue in https://github.com/bmewburn/vscode-intelephense/issues/2829
I am running Laravel v10.48.4. Rolling back to Intelephense 1.10.2 fixes the issue.
Do you have phpstorm metadata defined for app
? Or any other ide helper definition for it? If so can you post it.
Nope :/ there is nothing for app
in any meta file
Does a reindex fix it? ctrl + shift + p
-> Index workspace
@bmewburn it does not, the only thing that fixed it for me was a rollback to 1.10.2 and a reindex
Same thing in v1.10.4 + reindex
@bmewburn I did some more tests and the issue disappears if I delete .phpstorm.meta.php generated by barryvdh/laravel-ide-helper (php artisan ide-helper:meta) even though there is no app
override in the meta file
Can confirm the same behavior and "solution" as @eldair . Removing .phpstorm.meta.php
fixes the problem but this is obviously not a permanent solution. Running Laravel 10.47.0
with php 8.2.16
. Thanks.
I can confirm that fixes the issue as well. I don't know whether an easy solution is to prevent intelephense from scanning the .phpstorm.meta.php
file? It's not actual project code, just something PHPStorm generates
Anyone came up with a better solution? I'm also struggling with this.
I've done a little experimenting on Intelephense 1.10.4 and found a workaround for this issue. Adding an extra line to your .phpstorm.meta.php like so will allow Intelephense to correctly type the app()->make(MyClass::class)
syntax, as well as any other calls to app()
with no argument.
override(\app(0), map([
'' => '@',
'null' => \Illuminate\Contracts\Foundation\Application::class,
I believe Intelephense is examining the function's signature, app(?string $abstract = null, array $parameters = [])
, and using that default null
argument to infer the return type when no arguments are provided. Basically, it's looking up the type of app('null')
, and the PHPStorm metadata says that any string argument is treated as a class-string and by default will return an object of that type ('' => '@'
), unless it's overridden later on with a more specific type.
This workaround does mean that app('null')
will be accepted and treated identically to app()
, which isn't ideal, but you probably don't have a service named "null" and probably won't want to write app('null')
in your code.
I believe the correct behaviour on Intelephense's part would be to ignore this override
declaration completely unless the argument passed to app()
really is a string, because as far as I can tell from JetBrains' documentation, the map()
directive only works for string arguments anyway.
Describe the bug Previous version did not report an error when calling Laravel
app
helper and this one does.To Reproduce Calling
app
laravel helperExpected behavior No error to be shown
Screenshots
Platform and version VSCode running in wsl, 1.10.3 Intelephense version