[wp-trac] [WordPress Trac] #61930: size_format(): Inconsistent behaviour when zero bytes are passed
WordPress Trac
noreply at wordpress.org
Mon Sep 2 13:05:07 UTC 2024
#61930: size_format(): Inconsistent behaviour when zero bytes are passed
--------------------------+------------------------------
Reporter: marian1 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 6.6.1
Severity: trivial | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by devmooz):
This issue is indeed rooted in the strict comparison (===) used in the
size_format() function. The strict comparison checks not only the value
but also the type, so 0 === $bytes fails when $bytes is a string ('0').
Explanation:
Before WP 4.6.0: Both 0 (integer) and '0' (string) would cause
size_format() to return false because the condition likely used a loose
comparison (==), which checks only the value and not the type.
From WP 4.6.0 onwards: The strict comparison was introduced, so 0 ===
$bytes only returns true when $bytes is strictly an integer 0. If $bytes
is a string '0', the condition fails, and the function continues
processing, eventually returning '0 B' instead of false.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61930#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list