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

Typehint for $this in included file requires fully qualified name #10936

Open
Hackwar opened this issue Apr 25, 2024 · 1 comment
Open

Typehint for $this in included file requires fully qualified name #10936

Hackwar opened this issue Apr 25, 2024 · 1 comment
Labels

Comments

@Hackwar
Copy link

Hackwar commented Apr 25, 2024

Bug report

This is in part related to #7886.

First of all sorry for having issues to explain this properly. I'm a contributor to Joomla and our MVC system include()s layout files in the context of the view classes which only contain HTML and simple PHP. One example would be this: https://github.com/joomla/joomla-cms/blob/5.1-dev/administrator/components/com_actionlogs/tmpl/actionlogs/default.php

The code is executed in the class context of the view class and as you can see in the file, we try to typehint the class for $this. phpstan has been throwing errors for this when NOT using the fully namespaced class name. So when we have a use ...\HtmlView; statement for this at the top and then only reference the class as /** @var HtmlView $this */ in the layout, phpstan throws the error

Call to method ****** on an unknown class HtmlView.

Unfortunately I was unable to replicate this in the PHPStan playground. I thought it was related to the actual class, but when using the fully qualified name, it works fine. So /** @var \Joomla\Component\Actionlogs\Administrator\View\Actionlogs\HtmlView $this */ is fine with phpstan. The same typehint for any other variable also works fine, but using a different class name for $this again throws an error. So it seems that $this has a special handling which makes phpstan not understand the typehinting properly.

Code snippet that reproduces the problem

No response

Expected output

PHPStan should properly find the class.

Did PHPStan help you today? Did it make you happy in any way?

No response

Copy link

mergeable bot commented Apr 25, 2024

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

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

2 participants