[wp-trac] [WordPress Trac] #64742: PHP 8.5: Incorrect array access in `wp_get_attachment_image_src`

WordPress Trac noreply at wordpress.org
Mon Mar 30 00:16:34 UTC 2026


#64742: PHP 8.5: Incorrect array access in `wp_get_attachment_image_src`
-------------------------------------------------+-------------------------
 Reporter:  edent                                |       Owner:
                                                 |  westonruter
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  7.0.1
Component:  General                              |     Version:  4.4
 Severity:  minor                                |  Resolution:  fixed
 Keywords:  good-first-bug has-patch has-unit-   |     Focuses:  php-
  tests                                          |  compatibility
-------------------------------------------------+-------------------------
Changes (by westonruter):

 * owner:  (none) => westonruter
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"62176" 62176]:
 {{{
 #!CommitTicketReference repository="" revision="62176"
 Media: Guard against `false` return values from
 `wp_get_attachment_image_src()` and `wp_getimagesize()`.

 * Add `is_array()` checks before accessing return values from
 `wp_get_attachment_image_src()` in `get_oembed_response_data_rich()`,
 `wp_playlist_shortcode()`, and `wp_prepare_attachment_for_js()`.
 * Guard `wp_getimagesize()` calls within `wp_get_attachment_image_src()`
 itself.
 * Ensure `wp_get_attachment_image_src()` always returns the expected
 `array{0: string, 1: int, 2: int, 3: bool}` type or `false` by normalizing
 the filter result with explicit type casting and default values.
 * Add `@phpstan-return` annotations to both
 `wp_get_attachment_image_src()` and `wp_getimagesize()` for the specific
 array shapes.

 Developed in https://github.com/WordPress/wordpress-develop/pull/11073

 Props hbhalodia, westonruter, mukesh27, edent, ozgursar, roshniahuja14.
 Fixes #64742.
 }}}

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


More information about the wp-trac mailing list