Skip to content

fix: add updated signature for getenv #4009

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

Closed
wants to merge 2 commits into from

Conversation

msbit
Copy link

@msbit msbit commented May 22, 2025

Add the following signature for getenv:

 getenv(?string $name = null, bool $local_only = false): string|array|false

to the function map (specifically for PHP 8 and above). This replaces all existing signatures, and should fix 13065.

Add the following signature for `getenv`:

     getenv(?string $name = null, bool $local_only = false): string|array|false

to the function map (specifically for PHP 8 and above). This replaces all
existing signatures, and should fix [13065][1].

[1]: phpstan/phpstan#13065
@msbit
Copy link
Author

msbit commented May 22, 2025

@ondrejmirtes let me know if this is what you were expecting. It shows no error for the following:

<?php

getenv();
getenv(null);
getenv('TERM');
getenv(null, false);
getenv(null, true);
getenv('TERM', false);
getenv('TERM', true);

@msbit msbit force-pushed the fix/getenv-php-8 branch from 5d2ea0a to 8465238 Compare May 22, 2025 12:09
@msbit
Copy link
Author

msbit commented May 22, 2025

@ondrejmirtes I'm not sure about the interactions of optional arguments (name=) to allow this to replicate the no-argument override in the base function map. Do you have any advice?

@VincentLanglet
Copy link
Contributor

@msbit Fixed by #4007

@msbit msbit closed this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected error when passing null to getenv
2 participants