3v4l.org

run code in 300+ PHP versions simultaneously
<?php function max_by($collection, $property) { $plucked = array_map(function ($item) use ($property) { return $item->$property; }, $collection); return max($plucked); } class A { function __construct($u,$v) { $this->u = $u; $this->v = $v; } } $array = [ new A(1,3), 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/SMPF0
function name:  (null)
number of ops:  31
compiled vars:  !0 = $array, !1 = $a, !2 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $3      'A'
          1        SEND_VAL_EX                                              1
          2        SEND_VAL_EX                                              3
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~5      $3
   19     5        NEW                                              $6      'A'
          6        SEND_VAL_EX                                              2
          7        SEND_VAL_EX                                              2
          8        DO_FCALL                                      0          
          9        ADD_ARRAY_ELEMENT                                ~5      $6
   20    10        NEW                                              $8      'A'
         11        SEND_VAL_EX                                              3
         12        SEND_VAL_EX                                              1
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~5      $8
   17    15        ASSIGN                                                   !0, ~5
   23    16        INIT_FCALL                                               'max_by'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 'u'
         19        DO_FCALL                                      0  $11     
         20        ASSIGN                                                   !1, $11
   24    21        INIT_FCALL                                               'max_by'
         22        SEND_VAR                                                 !0
         23        SEND_VAL                                                 'v'
         24        DO_FCALL                                      0  $13     
         25        ASSIGN                                                   !2, $13
   25    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 = 62) Position 1 = -2
filename:       /in/SMPF0
function name:  max_by
number of ops:  14
compiled vars:  !0 = $collection, !1 = $property, !2 = $plucked
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSMPF0%3A4%240'
          4        BIND_LEXICAL                                             ~3, !1
    6     5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
    4     8        ASSIGN                                                   !2, $4
    7     9        INIT_FCALL                                               'max'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $6      
         12      > RETURN                                                   $6
    8    13*     > RETURN                                                   null

End of function max_by

Function %00%7Bclosure%7D%2Fin%2FSMPF0%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SMPF0
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $item, !1 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    5     2        FETCH_OBJ_R                                      ~2      !0, !1
          3      > RETURN                                                   ~2
    6     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FSMPF0%3A4%240

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

End of function __construct

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.52 ms | 1394 KiB | 21 Q