Make WordPress Core

Changeset 63158


Ignore:
Timestamp:
08/07/2026 07:12:29 PM (5 weeks ago)
Author:
dmsnell
Message:

Docs: Revert "Indicate absint() returns non-negative-int...".

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: https://github.com/WordPress/wordpress-develop/pull/12940
Discussed in: https://core.trac.wordpress.org/ticket/65826

Follow-up to [62647].

Props dmsnell, josephscott, westonruter.
Fixes #65826. See #64898.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r62647 r63158  
    14651465 * @param mixed $maybeint Data you wish to have converted to a non-negative integer.
    14661466 * @return int A non-negative integer.
    1467  * @phpstan-return non-negative-int
    1468  */
    1469 function absint( $maybeint ): int {
     1467 */
     1468function absint( $maybeint ) {
    14701469        return abs( (int) $maybeint );
    14711470}
  • trunk/tests/phpstan/baselines/argument.type.neon

    r63024 r63158  
    5757                        message: '#^Parameter \#1 \$text of function esc_attr expects string, int given\.$#'
    5858                        identifier: argument.type
    59                         count: 3
    60                         path: ../../../src/wp-admin/edit-comments.php
    61                 -
    62                         message: '#^Parameter \#1 \$text of function esc_attr expects string, int\<0, max\> given\.$#'
    63                         identifier: argument.type
    64                         count: 1
     59                        count: 4
    6560                        path: ../../../src/wp-admin/edit-comments.php
    6661                -
     
    575570                        path: ../../../src/wp-admin/nav-menus.php
    576571                -
    577                         message: '#^Parameter \#2 \$menu_data of function wp_save_nav_menu_items expects array\<array\>, int\<0, max\> given\.$#'
     572                        message: '#^Parameter \#2 \$menu_data of function wp_save_nav_menu_items expects array\<array\>, int given\.$#'
    578573                        identifier: argument.type
    579574                        count: 1
     
    715710                        path: ../../../src/wp-content/themes/twentyeleven/inc/theme-options.php
    716711                -
    717                         message: '#^Parameter \#1 \$text of function esc_attr expects string, int\<0, max\> given\.$#'
     712                        message: '#^Parameter \#1 \$text of function esc_attr expects string, int given\.$#'
    718713                        identifier: argument.type
    719714                        count: 1
     
    780775                        path: ../../../src/wp-content/themes/twentyfourteen/inc/widgets.php
    781776                -
    782                         message: '#^Parameter \#1 \$text of function esc_attr expects string, int\<0, max\> given\.$#'
     777                        message: '#^Parameter \#1 \$text of function esc_attr expects string, int given\.$#'
    783778                        identifier: argument.type
    784779                        count: 1
     
    810805                        path: ../../../src/wp-content/themes/twentynineteen/template-parts/post/author-bio.php
    811806                -
    812                         message: '#^Parameter \#1 \$text of function esc_attr expects string, int\<0, max\> given\.$#'
     807                        message: '#^Parameter \#1 \$text of function esc_attr expects string, int given\.$#'
    813808                        identifier: argument.type
    814809                        count: 1
  • trunk/tests/phpstan/baselines/notIdentical.alwaysTrue.neon

    r63023 r63158  
    1919parameters:
    2020        ignoreErrors:
    21                 -
    22                         message: '#^Strict comparison using \!\=\= between ''all'' and int will always evaluate to true\.$#'
    23                         identifier: notIdentical.alwaysTrue
    24                         count: 1
    25                         path: ../../../src/wp-admin/includes/class-wp-links-list-table.php
    2621                -
    2722                        message: '#^Strict comparison using \!\=\= between null and string will always evaluate to true\.$#'
Note: See TracChangeset for help on using the changeset viewer.