Make WordPress Core

Changes between Initial Version and Version 2 of Ticket #44123


Ignore:
Timestamp:
05/17/2018 02:22:37 PM (7 years ago)
Author:
desrosj
Comment:

Description edits

  • Added link to the 4.9.6 dev note.
  • Added examples from the dev note.
  • Added clarification of the ticket's purpose.
  • Remove coding-standards focus (this is more "best practices").

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #44123

    • Property Keywords needs-patch added
    • Property Focuses coding-standards removed
    • Property Milestone changed from Awaiting Review to 4.9.7
  • Ticket #44123 – Description

    initial v2  
    11In 4.9.6, polyfills for `is_countable()` and `is_iterable()` were introduced (#43583 and #43619). These should be utilized in core for better variable validation and forwards compatibility.
    22
    3 This is a meta ticket to track overall progress making replacements throughout core. Because there will be many instances and each requires validation, individual tickets should be opened for each replacement.
     3This is a meta ticket to track overall progress making replacements throughout core. Because there will be many instances and each requires validation, individual tickets should be opened for each patch.
     4
     5**If you have reviewed any core files, please add a note in this ticket about which files you have reviewed and reference any tickets with patches that you have opened as a result of your review.**
     6
     7Dev note detailing the new polyfills: https://make.wordpress.org/core/2018/05/17/new-php-polyfills-in-4-9-6/
     8
     9== Using `is_countable()`
     10
     11=== Old Way
     12
     13{{{
     14if ( count( $var ) > 0 ) {
     15        // Do something.
     16}
     17}}}
     18
     19=== New Way
     20
     21{{{
     22if ( is_countable( $var ) && count( $var ) > 0 ) {
     23        // Do something.
     24}
     25}}}
     26
     27== Using `is_iterable()`
     28
     29=== Old Way
     30
     31{{{
     32if ( count( $var ) > 0 ) {
     33        foreach( $var as $key => $value) {
     34                // Do something.
     35        }
     36}
     37}}}
     38
     39=== New Way
     40
     41{{{
     42if ( is_iterable( $var ) ) {
     43        foreach( $var as $key => $value) {
     44                // Do something.
     45        }
     46}
     47}}}