[wp-trac] [WordPress Trac] #55678: Avoid `filesize()` warnings when storing file size in media metadata

WordPress Trac noreply at wordpress.org
Wed May 4 14:18:05 UTC 2022


#55678: Avoid `filesize()` warnings when storing file size in media metadata
--------------------------+-------------------------
 Reporter:  johnbillion   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  6.0
Component:  Media         |    Version:  trunk
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-------------------------
 As reported by Cybr in [comment:61:ticket:49412]:

 ----

 `filesize()` generates an `E_WARNING` in case of an error
 [https://www.php.net/manual/en/function.filesize.php (source)]. The `@`
 operator would suppress that. I see that operator is primarily used when
 handling files in WP; whether or not justified is concerned in #24780, as
 mentioned in comment:55.

 If we agree not using the Error Suppression operator, it'd be better to
 use
 `$size = file_exists( $path ) ? (int) filesize( $path ) : 0;`
 Casting to `(int)` is still required because PHP returns `false` on error,
 for whatever reason that might happen.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55678>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list