3v4l.org

run code in 300+ PHP versions simultaneously
<?php // test data class Foo { private $a; private $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } public function getA() { return $this->a; } public function getB() { return $this->b; } } $list = [ $foo1 = new Foo(2, "bar"), $foo2 = new Foo(5, "baz"), $foo3 = new Foo(1, "bam"), ]; // simple $isGreater = function($carry, $item) { return is_null($carry) || $item->getA() > $carry->getA() ? $item : $carry; }; $maxOfList = array_reduce($list, $isGreater); assert($maxOfList === $foo2); // reusable max() function $max = function($list, callable $extract) { $compare = function($carry, $item) use($extract) { return is_null($carry) || $extract($item) > $extract($carry) ? $item : $carry; }; return array_reduce($list, $compare); }; $extractA = function($x) { return $x->getA();}; assert($max($list, $extractA) === $foo2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IqmVh
function name:  (null)
number of ops:  47
compiled vars:  !0 = $list, !1 = $foo1, !2 = $foo2, !3 = $foo3, !4 = $isGreater, !5 = $maxOfList, !6 = $max, !7 = $extractA
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $8      'Foo'
          1        SEND_VAL_EX                                              2
          2        SEND_VAL_EX                                              'bar'
          3        DO_FCALL                                      0          
          4        ASSIGN                                           ~10     !1, $8
          5        INIT_ARRAY                                       ~11     ~10
   21     6        NEW                                              $12     'Foo'
          7        SEND_VAL_EX                                              5
          8        SEND_VAL_EX                                              'baz'
          9        DO_FCALL                                      0          
         10        ASSIGN                                           ~14     !2, $12
         11        ADD_ARRAY_ELEMENT                                ~11     ~14
   22    12        NEW                                              $15     'Foo'
         13        SEND_VAL_EX                                              1
         14        SEND_VAL_EX                                              'bam'
         15        DO_FCALL                                      0          
         16        ASSIGN                                           ~17     !3, $15
         17        ADD_ARRAY_ELEMENT                                ~11     ~17
   19    18        ASSIGN                                                   !0, ~11
   28    19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIqmVh%3A28%240'
         20        ASSIGN                                                   !4, ~19
   32    21        INIT_FCALL                                               'array_reduce'
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $21     
         25        ASSIGN                                                   !5, $21
   33    26        ASSERT_CHECK                                             
         27        INIT_FCALL                                               'assert'
         28        IS_IDENTICAL                                     ~23     !5, !2
         29        SEND_VAL                                                 ~23
         30        SEND_VAL                                                 'assert%28%24maxOfList+%3D%3D%3D+%24foo2%29'
         31        DO_ICALL                                                 
   38    32        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIqmVh%3A38%241'
         33        ASSIGN                                                   !6, ~25
   45    34        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIqmVh%3A45%243'
         35        ASSIGN                                                   !7, ~27
   46    36        ASSERT_CHECK                                             
         37        INIT_FCALL                                               'assert'
         38        INIT_DYNAMIC_CALL                                        !6
         39        SEND_VAR_EX                                              !0
         40        SEND_VAR_EX                                              !7
         41        DO_FCALL                                      0  $29     
         42        IS_IDENTICAL                                     ~30     !2, $29
         43        SEND_VAL                                                 ~30
         44        SEND_VAL                                                 'assert%28%24max%28%24list%2C+%24extractA%29+%3D%3D%3D+%24foo2%29'
         45        DO_ICALL                                                 
         46      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FIqmVh%3A28%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/IqmVh
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2        TYPE_CHECK                                    2  ~2      !0
          3      > JMPNZ_EX                                         ~2      ~2, ->10
          4    >   INIT_METHOD_CALL                                         !1, 'getA'
          5        DO_FCALL                                      0  $3      
          6        INIT_METHOD_CALL                                         !0, 'getA'
          7        DO_FCALL                                      0  $4      
          8        IS_SMALLER                                       ~5      $4, $3
          9        BOOL                                             ~2      ~5
         10    > > JMPZ                                                     ~2, ->13
         11    >   QM_ASSIGN                                        ~6      !1
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~6      !0
         14    > > RETURN                                                   ~6
   30    15*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIqmVh%3A28%240

Function %00%7Bclosure%7D%2Fin%2FIqmVh%3A38%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IqmVh
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $list, !1 = $extract, !2 = $compare
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIqmVh%3A39%242'
          3        BIND_LEXICAL                                             ~3, !1
          4        ASSIGN                                                   !2, ~3
   42     5        INIT_FCALL                                               'array_reduce'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $5      
          9      > RETURN                                                   $5
   43    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIqmVh%3A38%241

Function %00%7Bclosure%7D%2Fin%2FIqmVh%3A39%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/IqmVh
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $carry, !1 = $item, !2 = $extract
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   40     3        TYPE_CHECK                                    2  ~3      !0
          4      > JMPNZ_EX                                         ~3      ~3, ->13
          5    >   INIT_DYNAMIC_CALL                                        !2
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $4      
          8        INIT_DYNAMIC_CALL                                        !2
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $5      
         11        IS_SMALLER                                       ~6      $5, $4
         12        BOOL                                             ~3      ~6
         13    > > JMPZ                                                     ~3, ->16
         14    >   QM_ASSIGN                                        ~7      !1
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~7      !0
         17    > > RETURN                                                   ~7
   41    18*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIqmVh%3A39%242

Function %00%7Bclosure%7D%2Fin%2FIqmVh%3A45%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IqmVh
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        INIT_METHOD_CALL                                         !0, 'getA'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIqmVh%3A45%243

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

End of function __construct

Function geta:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IqmVh
function name:  getA
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                      ~0      'a'
          1      > RETURN                                                   ~0
          2*     > RETURN                                                   null

End of function geta

Function getb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IqmVh
function name:  getB
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   FETCH_OBJ_R                                      ~0      'b'
          1      > RETURN                                                   ~0
          2*     > RETURN                                                   null

End of function getb

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.94 ms | 1408 KiB | 17 Q