Skip to content

Update functionMap.php#461

Merged
szepeviktor merged 3 commits intophp-stubs:masterfrom
PeterSmith8nss:master
Apr 8, 2026
Merged

Update functionMap.php#461
szepeviktor merged 3 commits intophp-stubs:masterfrom
PeterSmith8nss:master

Conversation

@PeterSmith8nss
Copy link
Copy Markdown
Contributor

Apply changes to funcation map for #460

Apply changes to funcation map for php-stubs#460
@szepeviktor
Copy link
Copy Markdown
Member

@johnbillion Please comment on this.

@PeterSmith8nss
Copy link
Copy Markdown
Contributor Author

PeterSmith8nss commented Mar 31, 2026 via email

@szepeviktor
Copy link
Copy Markdown
Member

Should I have updated the generated file wordpress-stubs.php as well

No.
Just wait for a few comments.

@johnbillion
Copy link
Copy Markdown
Contributor

This appears technically correct, but I'm sure there are dozens or hundreds more functions that are impure.

What's the effect of marking them as such?

@szepeviktor
Copy link
Copy Markdown
Member

hundreds more functions that are impure.

I deeply agree with that.

@PeterSmith8nss
Copy link
Copy Markdown
Contributor Author

PeterSmith8nss commented Mar 31, 2026 via email

@IanDelMar
Copy link
Copy Markdown
Contributor

@johnbillion PHPStan, by default, considers functions that return a value to be pure, meaning that it assumes they return the same value for the same input arguments. This behaviour can be disabled in the config by setting rememberPossiblyImpureFunctionValues to false. Adding @phpstan-impure tells PHPStan not to make that assumption, even when rememberPossiblyImpureFunctionValues is true.

We have already added @phpstan-impure to some functions, for example random-value generators. Impurity is about values, not types, so an impure function returning a string will still return a string on every call, but PHPStan will no longer assume that foo() === foo(). See https://phpstan.org/r/fa6bc999-11ae-42ce-b864-c47fd45deddc. Adding @phpstan-impure would, for example, prevent PHPStan from reporting certain ... will always/never evaluate to ... errors and could avoid other issues caused by PHPStan remembering a return value that may in fact change.

Yes, a lot of WordPress functions are impure, probably most of them, because they depend on globals, database queries, filters (though we typically ignore filters anyway), or other external state.

I think that get_transient() and wp_mail() are good candidates for adding @phpstan-impure. The fact that many other WordPress functions are also impure and not marked as such does not seem to me to be an argument against adding it for these two. Hopefully, core will adopt it as well at some point.

@PeterSmith8nss Yes, you should regenerate wordpress-stubs.php. And yes, treating all functions as impure by default and marking pure ones explicitly would be much easier. Ideally, purity or impurity would be declared for all functions. However, that would require someone to review the entire WordPress code base. And that person should first try to have those additional tags added to core directly.

@johnbillion
Copy link
Copy Markdown
Contributor

I'm happy for this to go in as long as Viktor is.

@szepeviktor
Copy link
Copy Markdown
Member

szepeviktor commented Apr 4, 2026

Okay!
One more thing: Peter, please promise you don't send "impure only" PRs anymore. Thanks!

@PeterSmith8nss
Copy link
Copy Markdown
Contributor Author

Have now added generated file.
I promise no more PRs re "impure only"
Personally, I'm adopting "rememberPossiblyImpureFunctionValues: false" as a safer approach. I'd rather have the odd false-positive than miss something because PhpStan wrongly assumed something was Pure.

Comment thread functionMap.php Outdated
Remove trailing spaces
@szepeviktor
Copy link
Copy Markdown
Member

Thank you, Peter.

@szepeviktor szepeviktor merged commit e69c429 into php-stubs:master Apr 8, 2026
8 checks passed
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.

4 participants