-
-
Notifications
You must be signed in to change notification settings - Fork 897
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
Allow to get defined variables from scope that are maybe defined #11772
Labels
Comments
Had to create this ugly thing to be able to retrieve them: $builder = ConstantArrayTypeBuilder::createEmpty();
foreach ($variables as $variable) {
$builder->setOffsetValueType(new ConstantStringType($variable), $scope->getVariableType($variable));
}
foreach ($scope->debug() as $key => $value) {
if ( ! str_starts_with($key, '$')) {
continue;
}
if ( ! str_ends_with($key, ' (Maybe)')) {
continue;
}
$variable = substr($key, 1, -8);
$builder->setOffsetValueType(new ConstantStringType($variable), $scope->getVariableType($variable), true);
}
return $builder->getArray(); |
Oh, that's a creative hack 😂 I'd accept a PR that adds |
Done in phpstan/phpstan-src#3521 |
ruudk
added a commit
to ruudk/phpstan-src
that referenced
this issue
Oct 1, 2024
Implemented phpstan/phpstan-src#3521 |
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Feature request
Currently,
Scope::getDefinedVariables()
only returns certain variables.How to retrieve variables that are maybe defined?
https://github.com/phpstan/phpstan-src/blob/f38addda2b151b6e41a746a37659c0bbe9e2293b/src/Analyser/MutatingScope.php#L557-L572
Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: