#58139 closed enhancement (fixed)
Use strict type comparison in wp-admin/includes/class-wp-ms-sites-list-table.php
| Reported by: | mujuonly | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.3 |
| Component: | Networks and Sites | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | multisite |
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
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.
#8
@
3 years ago
- Summary Strict type comparison → 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Use === instead of == in wp-admin/includes/class-wp-ms-sites-list-table.php
Trac ticket: https://core.trac.wordpress.org/ticket/58139