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

is_a: if third argument is false then do not allow string in first argument #4371

Closed
eigan opened this issue Jan 13, 2021 · 5 comments
Closed

Comments

@eigan
Copy link

eigan commented Jan 13, 2021

Feature request

https://www.php.net/manual/en/function.is-a.php

If this parameter set to false, string class name as object is not allowed.

PHPStan could report that a string is sent in this case:
https://phpstan.org/r/44b40ab5-7c7f-4ced-8048-e084d3d63f1d

b1rdex added a commit to b1rdex/phpstan-src that referenced this issue Jan 31, 2021
b1rdex added a commit to b1rdex/phpstan-src that referenced this issue Jan 31, 2021
b1rdex added a commit to b1rdex/phpstan-src that referenced this issue Jan 31, 2021
@staabm
Copy link
Contributor

staabm commented May 12, 2022

we had the same issue today: https://phpstan.org/r/a797fd58-43c7-4db3-a4b9-b6fb892627c9

will put this issue on my todo list

@rvanvelzen
Copy link
Contributor

Adding a conditional parameter in stubs should work (same for is_subclass_of):

/**
 * @param ($allow_string is true ? object|string : object) $object_or_class
 */
function is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool {}

@staabm
Copy link
Contributor

staabm commented May 12, 2022

it sounds too good to be true. need to try that immediately :-)

@ondrejmirtes
Copy link
Member

Implemented: phpstan/phpstan-src#1311

@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 Jun 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants