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

Static constant fetch makes it mixed #4361

Closed
b1rdex opened this issue Jan 12, 2021 · 8 comments
Closed

Static constant fetch makes it mixed #4361

b1rdex opened this issue Jan 12, 2021 · 8 comments

Comments

@b1rdex
Copy link
Contributor

b1rdex commented Jan 12, 2021

https://phpstan.org/r/5910f8db-19f2-4778-be67-0f7af32078aa

The questions/proposals are in the code.

class HelloWorld
{
	public const TEST = 1;
	/** @var int */
	public const TEST2 = 1;
	
	public function sayHello(): void
	{
		\PHPStan\dumpType(self::TEST); // 1, all is ok
		\PHPStan\dumpType(static::TEST); // mixed?
		\PHPStan\dumpType(static::TEST2); // mixed too, despite the phpdoc?
	}
}

class z extends HelloWorld {
	public const TEST = 'z'; // should be reported IMO, atleast on strict types
	public const TEST2 = 'z'; // should be reported IMO too, atleast when certain phpdoc types enabled
}
@mergeable mergeable bot closed this as completed Jan 12, 2021
@mergeable
Copy link

mergeable bot commented Jan 12, 2021

Hi there! 👋

Looks like you opened an issue without following one of the issue templates:

Bug report 🐛 (open an issue)

If something isn't working as expected 🤔.

Feature request 🚀 (open an issue)

I have a suggestion (and may want to implement it 🙂)!

Support question ❓ (open a discussion)

I need some help with my code because PHPStan doesn't like it.


The current issue will be closed. This is a precaution to save maintainer's time, I hope you'll understand.

Sincerely, the bot 🤖

@ondrejmirtes
Copy link
Member

Hi, the bot keeps closing your issue because you're leaving out the headline "Bug report" :) But I might change the behavior so that if the body text contains phpstan.org link, it won't be closed.

@b1rdex
Copy link
Contributor Author

b1rdex commented Jan 12, 2021

@ondrejmirtes, something is broken with the bot 😅 I tried to recreate #4360, and it closed this again.

@ondrejmirtes
Copy link
Member

@b1rdex You're not supposed to delete the whole template :) About your proposal, it's more of a feature request. Overriden constant types are not enforced and the PHPDoc isn't read at all.

@b1rdex
Copy link
Contributor Author

b1rdex commented Jan 12, 2021

Ok. Could you please reopen one of the issues and mark it as a feature request? I was very surprised to find mixed there.

@phpstan-bot
Copy link
Contributor

@b1rdex After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 11: Dumped type: 1
 12: Dumped type: mixed
-13: Dumped type: mixed
+13: Dumped type: int
Full report
Line Error
11 Dumped type: 1
12 Dumped type: mixed
13 Dumped type: int

@ondrejmirtes
Copy link
Member

Implemented by: phpstan/phpstan-src@b932769

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants