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
Type of $_GET
#1087
Comments
That might be quite tricky since $_GET is not read-only: https://3v4l.org/qLFMP . And it's superglobal nature further complicates things, since it could be assigned anywhere. |
Sorry, I haven't been very precise here. I wasn't talking about a universal annotation that should apply to But there are situations where we capture the content of
or
|
It's implemented in src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php if (in_array(
$stmt->name,
[
'GLOBALS',
'_SERVER',
'_GET',
'_POST',
'_FILES',
'_COOKIE',
'_SESSION',
'_REQUEST',
'_ENV',
],
true
)
) {
$stmt->inferredType = Type::getArray();
$context->vars_in_scope['$' . $stmt->name] = Type::getArray();
$context->vars_possibly_in_scope['$' . $stmt->name] = true;
return null;
} It's easy to do, the main issue is deciding what you want to do. E.g. My thoughts would be to use the following union types, or something similar (will have false positives in the very rare cases when you use integers as keys): I don't think psalm supports recursive union types, or that there are plans to [
'_GET' => 'array<string,string|string[]>', // or array<string,string|array>, if you want to support arbitrary nesting - same for the others
'_POST' => 'array<string,string|string[]>',
'_COOKIE' => 'array<string,string|string[]>',
'_REQUEST' => 'array<string,string|string[]>',
'_SERVER' => 'array<string,mixed>',
'_ENV' => 'array<string,string>',
'_FILES' => 'array<string,array<string,int|string|array<string,int|string>>>', // Can have multiple files with the same name.
'_SESSION' => 'array<string,mixed>',
'GLOBALS' => 'array<string,mixed>',
] |
Does Phan? |
No |
Fixed by #1430 |
Is there a way to specify the type of
$_GET
superglobal (or alternatively the result's type ofparse_str
)?With recursive types it would be something like
The text was updated successfully, but these errors were encountered: