#53540 closed defect (bug) (fixed)
Use $image[0] instead of $image['0'] in media file
Reported by: | chintan1896 | Owned by: | audrasjb |
---|---|---|---|
Milestone: | 5.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch good-first-bug |
Focuses: | Cc: |
Description
I think we need to use $image[0]
instead of $image['0']
in media file.
When called for srcset that time we have used $image[0]
Please check here. https://github.com/WordPress/WordPress/blob/master/wp-includes/media.php#L1218
Attachments (2)
Change History (17)
#3
in reply to:
↑ 2
@
3 years ago
Replying to adamsilverstein:
@chintan1896 thanks for the patch. I'm curious why you noticed this issue, did it create a warning or error in your system? Or was it more something you noticed when reviewing the source code?
When using arrays, PHP will automatically cast the '0' string to 0 int, so this is more of a cosmetic fix than functional, is that right?
I have noticed when reviewing the source code. Yes, you are right this is a cosmetic fix. I have suggested for code consistency. We have used 0 in https://github.com/WordPress/WordPress/blob/master/wp-includes/media.php#L1218
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
3 years ago
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
3 years ago
This ticket was mentioned in Slack in #core-media by sabernhardt. View the logs.
3 years ago
#9
@
3 years ago
Here's a link to confirm that this change will still work: https://3v4l.org/L7aNL
This change is worth making for the following reasons:
- Readability - When scanning code, single- or double-quoted array keys will read as associative arrays at first glance. This change makes it immediately clear that this is a numeric array.
- Performance - See the "Time with string|int" results in the output of the link above.
- Consistency - Numeric keys should be written as integers.
- Cross-version PHP support - As shown in the link above, this change will work across PHP versions.
IMO, this patch is ready for commit
in time for Beta 1 today.
Any other occurrences of numeric string
keys in core should be removed in a follow-up ticket.
A regex search for \[( )?'[0-9]'( )?\]
returns the following additional files:
src/wp-admin/includes/media.php
(6)src/wp-includes/js/dist/components.js
(1)src/wp-includes/js/dist/components.js.map
(1)src/wp-includes/js/dist/editor.js
(1)src/wp-includes/js/dist/editor.js.map
(1)
These can have the same change made.
Searches for more than single digit numeric keys only shows ['01']
, ['02']
... which refer to months. This would probably have been better implemented as a numeric array with the leading zeroes added when needed, but any changes would require investigation for potential BC and performance issues.
This ticket was mentioned in Slack in #core by costdev. View the logs.
3 years ago
This ticket was mentioned in PR #1942 on WordPress/wordpress-develop by audrasjb.
3 years ago
#11
Trac ticket: https://core.trac.wordpress.org/ticket/53540
3 years ago
#15
Committed in https://core.trac.wordpress.org/changeset/52245
@chintan1896 thanks for the patch. I'm curious why you noticed this issue, did it create a warning or error in your system? Or was it more something you noticed when reviewing the source code?
When using arrays, PHP will automatically cast the '0' string to 0 int, so this is more of a cosmetic fix than functional, is that right?