[wp-trac] [WordPress Trac] #43844: PHP list language construct changed behaviour in PHP 7

WordPress Trac noreply at wordpress.org
Sun Aug 12 23:02:48 UTC 2018


#43844: PHP list language construct changed behaviour in PHP 7
----------------------------+-----------------------------------
 Reporter:  javorszky       |       Owner:  SergeyBiryukov
     Type:  defect (bug)    |      Status:  reviewing
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:
 Severity:  major           |  Resolution:
 Keywords:  dev-feedback    |     Focuses:  docs, administration
----------------------------+-----------------------------------

Comment (by jrf):

 @javorszky Please help me out. I've been looking at the code related to
 this and I cannot find the code using the PHP `list` construct which is
 related to this behaviour which you refer to.

 The class calls the `get_sortable_columns()` method on line 1019, filters
 it and then walks through it and correctly takes both string as well as
 array input into account as is attested by the `$data = (array) $data` on
 line 1038 and will set array key `1` (orderby) to `false` if it's not
 found, so it's quite unclear to me how what you refer to is even possible
 (error-wise).

 See: https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes
 /class-wp-list-table.php#L1019-L1044

 Other than that, neither of the two PHP changes you refer to are relevant
 in any case, not even when `$sortable` is used in the
 `print_column_headers()` method (line 1117).

 The first one "Strings can no longer be unpacked" is irrelevant as, as per
 the above, it will always be an array.
 What is meant by that PHP native change is that you can no longer do this:
 {{{#!php
 <?php
 list( $char1, $char2, $char3 ) = 'cat';
 }}}


 The second one "List order change" is irrelevant as well, as that only
 applies to lists assigning the variables into an array without setting the
 key or to the same variable twice, i.e.:
 {{{#!php
 <?php
 list( $a[], $a[] ) = array( 'cat', 'dog' );
 list( $animal, $animal ) = array( 'cat', 'dog' );
 }}}
 are both affected, but
 {{{#!php
 <?php
 list( $miauw, $woof ) = array( 'cat', 'dog' );
 }}}
 would not be affected.

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


More information about the wp-trac mailing list