-
Notifications
You must be signed in to change notification settings - Fork 668
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
Problem with $_ENV #3564
Comments
I found these snippets: https://psalm.dev/r/084f2df25d<?php
class EnvVarUtil
{
public static function get(string $name, string $default = ''): string
{
return getenv($name) ?: (string) $_ENV[$name] ?? $default;
}
}
|
Shouldn't the last ternary be wrapped in parens? |
I found these snippets: https://psalm.dev/r/f48b8a52dc<?php
class EnvVarUtil
{
public static function get(string $name, string $default = ''): string
{
return getenv($name) ?: (string) ($_ENV[$name] ?? $default);
}
}
|
Thanks, I hadn't considered this syntax and actually don't understand why in this way works. |
It's about operator precedence – when in doubt, parenthesize |
@muglug some updates lead me to reopen this issue https://psalm.dev/r/f48b8a52dc |
I found these snippets: https://psalm.dev/r/f48b8a52dc<?php
class EnvVarUtil
{
public static function get(string $name, string $default = ''): string
{
return getenv($name) ?: (string) ($_ENV[$name] ?? $default);
}
}
|
@matiux please open a new issue. It appears someone thought psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php Lines 674 to 707 in d0be59e
|
I have this function to take environment variables in various ways
https://psalm.dev/r/084f2df25d
But I'm struggling to figure out how to solve the TypeDoesNotContainType error
The text was updated successfully, but these errors were encountered: