#58139 closed enhancement (fixed)
Use strict type comparison in wp-admin/includes/class-wp-ms-sites-list-table.php
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.3 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Networks and Sites | Keywords: | has-patch |
| Focuses: | multisite | Cc: |
Description
Use === instead of == in wp-admin/includes/class-wp-ms-sites-list-table.php
Change History (9)
This ticket was mentioned in PR #4334 on WordPress/wordpress-develop by @mujuonly.
3 years ago
#1
- Keywords has-patch added; needs-patch removed
#2
@
3 years ago
- Version 6.2 deleted
Thanks for opening this ticket and for the PR.
I have not looked deeply into this, but are we sure that $blog['deleted'], $blog['archived'] and $blog['spam'] are string type? Shouldn't we cast them into a string?
#3
follow-up:
↓ 4
@
3 years ago
Even if those are strings this condition checks if each has value '1' it means true
cast to (string) won't change anything here
<?php if ( '1' == $blog['deleted'] ) {}
we can simply reverse the condition and use ===
<?php if ( $blog['deleted'] === '1' ) {}
#4
in reply to:
↑ 3
@
3 years ago
Replying to jankyz:
Even if those are strings this condition checks if each has value '1' it means true
cast to (string) won't change anything here
<?php if ( '1' == $blog['deleted'] ) {}we can simply reverse the condition and use
===
<?php if ( $blog['deleted'] === '1' ) {}
It is good to use the Yoda condition here according to standards.
#5
@
3 years ago
Thanks for the PR! I have confirmed that these values are indeed strings as returned from get_sites() via WP_MS_Sites_List_Table::prepare_items().
They match the WP_Site class properties of the same name, which are also defined as numeric strings, '1' or '0', for compatibility reasons.
#6
@
3 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 55656:
#8
@
3 years ago
- Summary changed from Strict type comparison to Use strict type comparison in wp-admin/includes/class-wp-ms-sites-list-table.php
@SergeyBiryukov commented on PR #4334:
3 years ago
#9
Thanks for the PR! Merged in r55656.
Use === instead of == in wp-admin/includes/class-wp-ms-sites-list-table.php
Trac ticket: https://core.trac.wordpress.org/ticket/58139