3v4l.org

run code in 500+ PHP versions simultaneously
<?php function __( $str ) { return $str; } function _doing_it_wrong( $func, $error_message, $version ) { trigger_error( $error_message, E_USER_NOTICE ); } class WP_List_Util { /** * The input array. * * @since 4.7.0 * @var array */ private $input = array(); /** * The output array. * * @since 4.7.0 * @var array */ private $output = array(); /** * Temporary arguments for sorting. * * @since 4.7.0 * @var string[] */ private $orderby = array(); /** * Constructor. * * Sets the input array. * * @since 4.7.0 * * @param array $input Array to perform operations on. */ public function __construct( $input ) { $this->output = $input; $this->input = $input; } public function pluck( $field, $index_key = null ) { $newlist = array(); if ( ! $index_key ) { /* * This is simple. Could at some point wrap array_column() * if we knew we had an array of arrays. */ foreach ( $this->output as $key => $value ) { if ( is_object( $value ) ) { if ( property_exists( $value, $field ) ) { $newlist[ $key ] = $value->$field; } } elseif ( is_array( $value ) ) { if ( array_key_exists( $field, $value ) ) { $newlist[ $key ] = $value[ $field ]; } } else { _doing_it_wrong( __METHOD__, __( 'Values for the input array must be either objects or arrays.' ), '6.2.0' ); } } $this->output = $newlist; return $this->output; } /* * When index_key is not set for a particular item, push the value * to the end of the stack. This is how array_column() behaves. */ foreach ( $this->output as $value ) { if ( is_object( $value ) ) { if ( property_exists( $value, $field ) ) { if ( property_exists( $value, $index_key ) ) { $newlist[ $value->$index_key ] = $value->$field; } else { $newlist[] = $value->$field; } } } elseif ( is_array( $value ) ) { if ( array_key_exists( $field, $value ) ) { if ( array_key_exists( $index_key, $value ) ) { $newlist[ $value[ $index_key ] ] = $value[ $field ]; } else { $newlist[] = $value[ $field ]; } } } else { // _doing_it_wrong( // __METHOD__, // __( 'Values for the input array must be either objects or arrays.' ), // '6.2.0' // ); } } $this->output = $newlist; return $this->output; } } function wp_list_pluck( $input_list, $field, $index_key = null ) { if ( ! is_array( $input_list ) ) { return array(); } $util = new WP_List_Util( $input_list ); return $util->pluck( $field, $index_key ); } /* * Test with an array of arrays. */ $input_list = array( array( '123' => '456' ), array( 'foo' => 'bar' ), array( 'foo' => 'baz' ), ); var_dump( array_column( $input_list, 'foo', null ) ); var_dump( wp_list_pluck( $input_list, 'foo', null ) ); /* * Test with an array of objects. */ $input_list = array( (object) array( '123' => '456' ), (object) array( 'foo' => 'bar' ), (object) array( 'foo' => 'baz' ), ); var_dump( wp_list_pluck( $input_list, 'foo', null ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EuHT5
function name:  (null)
number of ops:  33
compiled vars:  !0 = $input_list
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
  131     0  E >   ASSIGN                                                       !0, <array>
  137     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'array_column'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     'foo'
          5        SEND_VAL                                                     null
          6        DO_ICALL                                             $2      
          7        SEND_VAR                                                     $2
          8        DO_ICALL                                                     
  138     9        INIT_FCALL                                                   'var_dump'
         10        INIT_FCALL                                                   'wp_list_pluck'
         11        SEND_VAR                                                     !0
         12        SEND_VAL                                                     'foo'
         13        SEND_VAL                                                     null
         14        DO_FCALL                                          0  $4      
         15        SEND_VAR                                                     $4
         16        DO_ICALL                                                     
  144    17        CAST                                              8  ~6      <array>
         18        INIT_ARRAY                                           ~7      ~6
         19        CAST                                              8  ~8      <array>
         20        ADD_ARRAY_ELEMENT                                    ~7      ~8
         21        CAST                                              8  ~9      <array>
         22        ADD_ARRAY_ELEMENT                                    ~7      ~9
  143    23        ASSIGN                                                       !0, ~7
  148    24        INIT_FCALL                                                   'var_dump'
         25        INIT_FCALL                                                   'wp_list_pluck'
         26        SEND_VAR                                                     !0
         27        SEND_VAL                                                     'foo'
         28        SEND_VAL                                                     null
         29        DO_FCALL                                          0  $11     
         30        SEND_VAR                                                     $11
         31        DO_ICALL                                                     
         32      > RETURN                                                       1

Function __:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EuHT5
function name:  __
number of ops:  3
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1      > RETURN                                                       !0
    5     2*     > RETURN                                                       null

End of function __

Function _doing_it_wrong:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EuHT5
function name:  _doing_it_wrong
number of ops:  8
compiled vars:  !0 = $func, !1 = $error_message, !2 = $version
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    8     3        INIT_FCALL                                                   'trigger_error'
          4        SEND_VAR                                                     !1
          5        SEND_VAL                                                     1024
          6        DO_ICALL                                                     
    9     7      > RETURN                                                       null

End of function _doing_it_wrong

Function wp_list_pluck:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EuHT5
function name:  wp_list_pluck
number of ops:  17
compiled vars:  !0 = $input_list, !1 = $field, !2 = $index_key, !3 = $util
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
  117     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      null
  118     3        TYPE_CHECK                                      128  ~4      !0
          4        BOOL_NOT                                             ~5      ~4
          5      > JMPZ                                                         ~5, ->7
  119     6    > > RETURN                                                       <array>
  122     7    >   NEW                                                  $6      'WP_List_Util'
          8        SEND_VAR_EX                                                  !0
          9        DO_FCALL                                          0          
         10        ASSIGN                                                       !3, $6
  124    11        INIT_METHOD_CALL                                             !3, 'pluck'
         12        SEND_VAR_EX                                                  !1
         13        SEND_VAR_EX                                                  !2
         14        DO_FCALL                                          0  $9      
         15      > RETURN                                                       $9
  125    16*     > RETURN                                                       null

End of function wp_list_pluck

Class WP_List_Util:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EuHT5
function name:  __construct
number of ops:  6
compiled vars:  !0 = $input
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   45     0  E >   RECV                                                 !0      
   46     1        ASSIGN_OBJ                                                   'output'
          2        OP_DATA                                                      !0
   47     3        ASSIGN_OBJ                                                   'input'
          4        OP_DATA                                                      !0
   48     5      > RETURN                                                       null

End of function __construct

Function pluck:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 39
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 34
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 73
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 73
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 57
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 56
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 53
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
Branch analysis from position: 56
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 72
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 71
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 68
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
Branch analysis from position: 71
Branch analysis from position: 72
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
filename:       /in/EuHT5
function name:  pluck
number of ops:  79
compiled vars:  !0 = $field, !1 = $index_key, !2 = $newlist, !3 = $value, !4 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   50     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      null
   51     2        ASSIGN                                                       !2, <array>
   53     3        BOOL_NOT                                             ~6      !1
          4      > JMPZ                                                         ~6, ->39
   58     5    >   FETCH_OBJ_R                                          ~7      'output'
          6      > FE_RESET_R                                           $8      ~7, ->34
          7    > > FE_FETCH_R                                           ~9      $8, !3, ->34
          8    >   ASSIGN                                                       !4, ~9
   59     9        TYPE_CHECK                                      256          !3
         10      > JMPZ                                                         ~11, ->17
   60    11    >   FRAMELESS_ICALL_2                property_exists      ~12     !3, !0
         12      > JMPZ                                                         ~12, ->16
   61    13    >   FETCH_OBJ_R                                          ~14     !3, !0
         14        ASSIGN_DIM                                                   !2, !4
         15        OP_DATA                                                      ~14
   59    16    > > JMP                                                          ->33
   63    17    >   TYPE_CHECK                                      128          !3
         18      > JMPZ                                                         ~15, ->25
   64    19    >   ARRAY_KEY_EXISTS                                             !0, !3
         20      > JMPZ                                                         ~16, ->24
   65    21    >   FETCH_DIM_R                                          ~18     !3, !0
         22        ASSIGN_DIM                                                   !2, !4
         23        OP_DATA                                                      ~18
   63    24    > > JMP                                                          ->33
   68    25    >   INIT_FCALL                                                   '_doing_it_wrong'
   69    26        SEND_VAL                                                     'WP_List_Util%3A%3Apluck'
   70    27        INIT_FCALL                                                   '__'
         28        SEND_VAL                                                     'Values+for+the+input+array+must+be+either+objects+or+arrays.'
         29        DO_FCALL                                          0  $19     
         30        SEND_VAR                                                     $19
   71    31        SEND_VAL                                                     '6.2.0'
   68    32        DO_FCALL                                          0          
   58    33    > > JMP                                                          ->7
         34    >   FE_FREE                                                      $8
   76    35        ASSIGN_OBJ                                                   'output'
         36        OP_DATA                                                      !2
   78    37        FETCH_OBJ_R                                          ~22     'output'
         38      > RETURN                                                       ~22
   85    39    >   FETCH_OBJ_R                                          ~23     'output'
         40      > FE_RESET_R                                           $24     ~23, ->73
         41    > > FE_FETCH_R                                                   $24, !3, ->73
   86    42    >   TYPE_CHECK                                      256          !3
         43      > JMPZ                                                         ~25, ->57
   87    44    >   FRAMELESS_ICALL_2                property_exists      ~26     !3, !0
         45      > JMPZ                                                         ~26, ->56
   88    46    >   FRAMELESS_ICALL_2                property_exists      ~27     !3, !1
         47      > JMPZ                                                         ~27, ->53
   89    48    >   FETCH_OBJ_R                                          ~28     !3, !1
         49        FETCH_OBJ_R                                          ~30     !3, !0
         50        ASSIGN_DIM                                                   !2, ~28
         51        OP_DATA                                                      ~30
   88    52      > JMP                                                          ->56
   91    53    >   FETCH_OBJ_R                                          ~32     !3, !0
         54        ASSIGN_DIM                                                   !2
         55        OP_DATA                                                      ~32
   86    56    > > JMP                                                          ->72
   94    57    >   TYPE_CHECK                                      128          !3
         58      > JMPZ                                                         ~33, ->72
   95    59    >   ARRAY_KEY_EXISTS                                             !0, !3
         60      > JMPZ                                                         ~34, ->71
   96    61    >   ARRAY_KEY_EXISTS                                             !1, !3
         62      > JMPZ                                                         ~35, ->68
   97    63    >   FETCH_DIM_R                                          ~36     !3, !1
         64        FETCH_DIM_R                                          ~38     !3, !0
         65        ASSIGN_DIM                                                   !2, ~36
         66        OP_DATA                                                      ~38
   96    67      > JMP                                                          ->71
   99    68    >   FETCH_DIM_R                                          ~40     !3, !0
         69        ASSIGN_DIM                                                   !2
         70        OP_DATA                                                      ~40
   94    71    > > JMP                                                          ->72
   85    72    > > JMP                                                          ->41
         73    >   FE_FREE                                                      $24
  111    74        ASSIGN_OBJ                                                   'output'
         75        OP_DATA                                                      !2
  113    76        FETCH_OBJ_R                                          ~42     'output'
         77      > RETURN                                                       ~42
  114    78*     > RETURN                                                       null

End of function pluck

End of class WP_List_Util.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.1 ms | 3411 KiB | 20 Q