3v4l.org

run code in 300+ PHP versions simultaneously
<?php function max_by($collection, $property) { $maxElement = $collection[0]; for ($i=0; $i < sizeof($collection); $i++) { if ($collection[$i]->$property > $maxElement->$property) { $maxElement = $collection[$i]; } } return $maxElement; } class A { function __construct($u,$v) { $this->u = $u; $this->v = $v; } } $array = [ new A(1,5), new A(2,2), new A(3,1) ]; $a = max_by($array, 'u'); $b = max_by($array, 'v'); var_dump($a, $b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ei64b
function name:  (null)
number of ops:  31
compiled vars:  !0 = $array, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   NEW                                              $3      'A'
          1        SEND_VAL_EX                                              1
          2        SEND_VAL_EX                                              5
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~5      $3
   22     5        NEW                                              $6      'A'
          6        SEND_VAL_EX                                              2
          7        SEND_VAL_EX                                              2
          8        DO_FCALL                                      0          
          9        ADD_ARRAY_ELEMENT                                ~5      $6
   23    10        NEW                                              $8      'A'
         11        SEND_VAL_EX                                              3
         12        SEND_VAL_EX                                              1
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~5      $8
   20    15        ASSIGN                                                   !0, ~5
   26    16        INIT_FCALL                                               'max_by'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 'u'
         19        DO_FCALL                                      0  $11     
         20        ASSIGN                                                   !1, $11
   27    21        INIT_FCALL                                               'max_by'
         22        SEND_VAR                                                 !0
         23        SEND_VAL                                                 'v'
         24        DO_FCALL                                      0  $13     
         25        ASSIGN                                                   !2, $13
   28    26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !1
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Function max_by:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 6
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 6
Branch analysis from position: 17
Branch analysis from position: 6
Branch analysis from position: 13
filename:       /in/ei64b
function name:  max_by
number of ops:  19
compiled vars:  !0 = $collection, !1 = $property, !2 = $maxElement, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        FETCH_DIM_R                                      ~4      !0, 0
          3        ASSIGN                                                   !2, ~4
    5     4        ASSIGN                                                   !3, 0
          5      > JMP                                                      ->14
    6     6    >   FETCH_DIM_R                                      ~7      !0, !3
          7        FETCH_OBJ_R                                      ~8      ~7, !1
          8        FETCH_OBJ_R                                      ~9      !2, !1
          9        IS_SMALLER                                               ~9, ~8
         10      > JMPZ                                                     ~10, ->13
    7    11    >   FETCH_DIM_R                                      ~11     !0, !3
         12        ASSIGN                                                   !2, ~11
    5    13    >   PRE_INC                                                  !3
         14    >   COUNT                                            ~14     !0
         15        IS_SMALLER                                               !3, ~14
         16      > JMPNZ                                                    ~15, ->6
   10    17    > > RETURN                                                   !2
   11    18*     > RETURN                                                   null

End of function max_by

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

End of function __construct

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.58 ms | 1402 KiB | 17 Q