[wp-trac] [WordPress Trac] #63175: Tests: Improve Unit tests for 'wp_unique_id_from_values()'

WordPress Trac noreply at wordpress.org
Fri Mar 28 21:31:57 UTC 2025


#63175: Tests: Improve Unit tests for 'wp_unique_id_from_values()'
--------------------------------------+---------------------
 Reporter:  joemcgill                 |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  6.8
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  tests
--------------------------------------+---------------------

Comment (by peterwilsoncc):

 I finally found different systems I had access to that resulted in
 different hashes.

 It's definitely caused by inaccuracies with the handling of floating
 points in some configurations.

 It seems casting floats to strings increases the accuracy 🤷‍♂️:

 {{{
 $ wp shell
 wp> $v = 10.5363
 => phar:///usr/local/src/wp-cli/bin/wp/vendor/wp-cli/shell-
 command/src/WP_CLI/Shell/REPL.php:52:
 double(10.536300000000001)
 wp> (string) $v
 => phar:///usr/local/src/wp-cli/bin/wp/vendor/wp-cli/shell-
 command/src/WP_CLI/Shell/REPL.php:52:
 string(7) "10.5363"
 }}}

 I think the accuracy could be improved by doing so but I also don't think
 it's worth introducing a recursive function to do so. Instead I think it
 best to explain the issue in the functions docblock:

 > Different versions and configurations of PHP may produce different
 results due to the way they handle floating-point numbers. When using the
 generated ID for CSS classes, it is recommended to generate the CSS inline
 to ensure the styles apply correctly.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63175#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list