Revert "Docs: Indicate absint() returns non-negative-int for static analysis. - #12940
Revert "Docs: Indicate absint() returns non-negative-int for static analysis.#12940dmsnell wants to merge 2 commits into
absint() returns non-negative-int for static analysis.#12940Conversation
…ic analysis." Trac ticket: Core-65826 Replaces WordPress#12917 This reverts commit 395dd74. When the return-type annotation was added to `absint()` it failed to recoginize that the function can return `float` as well. In the cases where it does this, WordPress started crashing requests. Reverting remove the type constraint where PHP enforces it in order to avoid the fatal errors. Co-Authored-By: Joseph Scott <josephscott@git.wordpress.org> Co-Authored-By: Weston Ruter <westonruter@git.wordpress.org>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| - | ||
| message: '#^Strict comparison using \!\=\= between ''all'' and int will always evaluate to true\.$#' | ||
| identifier: notIdentical.alwaysTrue | ||
| count: 1 | ||
| path: ../../../src/wp-admin/includes/class-wp-links-list-table.php |
There was a problem hiding this comment.
I was confused why this error went away, but it makes sense to me now.
It's the int native type hint which makes PHPStan more strict, beyond the @return int type in phpdoc.
So with just PHPDoc saying it @return int, then if ( 'all' !== $cat_id ) { is not considered an error.
Since in theory the function could still return non-int and not be a PHP error.
But with a native int type hint, then it absolutely never can happen.
The introduction of a return-type annotation for `absint()` created fatal errors in cases where the function returns a `float` value. This resulted when the value passed into the function is smaller than `PHP_INT_MIN`. Since PHP’s `int` type is unable to represent the magnitude of that number in the positive, it returns a `float` value instead. Reverting the type annotation prevents the crashing, but additional follow-up is warranted to ensure that the function produces the expected return types. Developed in: #12940 Discussed in: https://core.trac.wordpress.org/ticket/65826 Follow-up to [62647]. Props dmsnell, josephscott, westonruter. Fixes #65826. See #64898. git-svn-id: https://develop.svn.wordpress.org/trunk@63158 602fd350-edb4-49c9-b593-d223f7449a82
The introduction of a return-type annotation for `absint()` created fatal errors in cases where the function returns a `float` value. This resulted when the value passed into the function is smaller than `PHP_INT_MIN`. Since PHP’s `int` type is unable to represent the magnitude of that number in the positive, it returns a `float` value instead. Reverting the type annotation prevents the crashing, but additional follow-up is warranted to ensure that the function produces the expected return types. Developed in: WordPress/wordpress-develop#12940 Discussed in: https://core.trac.wordpress.org/ticket/65826 Follow-up to [62647]. Props dmsnell, josephscott, westonruter. Fixes #65826. See #64898. Built from https://develop.svn.wordpress.org/trunk@63158 git-svn-id: http://core.svn.wordpress.org/trunk@62357 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The introduction of a return-type annotation for `absint()` created fatal errors in cases where the function returns a `float` value. This resulted when the value passed into the function is smaller than `PHP_INT_MIN`. Since PHP’s `int` type is unable to represent the magnitude of that number in the positive, it returns a `float` value instead. Reverting the type annotation prevents the crashing, but additional follow-up is warranted to ensure that the function produces the expected return types. Developed in: WordPress#12940 Discussed in: https://core.trac.wordpress.org/ticket/65826 Follow-up to [62647]. Props dmsnell, josephscott, westonruter. Fixes #65826. See #64898. git-svn-id: https://develop.svn.wordpress.org/trunk@63158 602fd350-edb4-49c9-b593-d223f7449a82
Trac ticket: Core-65826
Replaces #12917
This reverts commit 395dd74.
When the return-type annotation was added to
absint()it failed to recoginize that the function can returnfloatas well. In the cases where it does this, WordPress started crashing requests.Reverting remove the type constraint where PHP enforces it in order to avoid the fatal errors.