3v4l.org

run code in 300+ PHP versions simultaneously
<?php // SETUP CODE class A { function __construct($val) { $this->val = $val; } } $objs = [ new A(3), new A(5), new A(2), ]; // AMAZING max_by IMPL :P function max_by(array $array, $key) { $res = array_filter($array, function($o) use($key) { static $m; $val = is_array($o) ? $o[$key] : $o->$key; $m = max($val, $m); return $val == $m; }); return end($res); } var_dump(max_by($objs, 'val'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/G4n09
function name:  (null)
number of ops:  21
compiled vars:  !0 = $objs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   NEW                                              $1      'A'
          1        SEND_VAL_EX                                              3
          2        DO_FCALL                                      0          
          3        INIT_ARRAY                                       ~3      $1
   12     4        NEW                                              $4      'A'
          5        SEND_VAL_EX                                              5
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~3      $4
   13     8        NEW                                              $6      'A'
          9        SEND_VAL_EX                                              2
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~3      $6
   10    12        ASSIGN                                                   !0, ~3
   29    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'max_by'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 'val'
         17        DO_FCALL                                      0  $9      
         18        SEND_VAR                                                 $9
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function max_by:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/G4n09
function name:  max_by
number of ops:  14
compiled vars:  !0 = $array, !1 = $key, !2 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        INIT_FCALL                                               'array_filter'
          3        SEND_VAR                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FG4n09%3A20%240'
          5        BIND_LEXICAL                                             ~3, !1
   25     6        SEND_VAL                                                 ~3
          7        DO_ICALL                                         $4      
   20     8        ASSIGN                                                   !2, $4
   26     9        INIT_FCALL                                               'end'
         10        SEND_REF                                                 !2
         11        DO_ICALL                                         $6      
         12      > RETURN                                                   $6
   27    13*     > RETURN                                                   null

End of function max_by

Function %00%7Bclosure%7D%2Fin%2FG4n09%3A20%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/G4n09
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $o, !1 = $key, !2 = $m, !3 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   21     2        BIND_STATIC                                              !2
   22     3        TYPE_CHECK                                  128          !0
          4      > JMPZ                                                     ~4, ->8
          5    >   FETCH_DIM_R                                      ~5      !0, !1
          6        QM_ASSIGN                                        ~6      ~5
          7      > JMP                                                      ->10
          8    >   FETCH_OBJ_R                                      ~7      !0, !1
          9        QM_ASSIGN                                        ~6      ~7
         10    >   ASSIGN                                                   !3, ~6
   23    11        INIT_FCALL                                               'max'
         12        SEND_VAR                                                 !3
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !2, $9
   24    16        IS_EQUAL                                         ~11     !3, !2
         17      > RETURN                                                   ~11
   25    18*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FG4n09%3A20%240

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

End of function __construct

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.67 ms | 1403 KiB | 22 Q