3v4l.org

run code in 300+ PHP versions simultaneously
<?php // test data class Foo { private $a; public function __construct($a) { $this->a = (int) $a; } public function hasGreaterAThan(self $another) { return $this->a > $another->a; } } $list = [ $foo1 = new Foo(2), $foo2 = new Foo(5), $foo3 = new Foo(1), ]; /** * Finds an item in a list via a comparison function * * @param array $aList the collection to examine * @param callable $comparison should compare two arguments and return a bool * @return mixed */ $find_by = function(array $aList, callable $comparison) { $callback = function($carry, $item) use ($comparison) { return ($carry == null || $comparison($item, $carry)) ? $item : $carry; }; return array_reduce($aList, $callback); }; $greaterA = function(Foo $foo1, Foo $foo2) { return $foo1->hasGreaterAThan($foo2); }; $lesserA = function(Foo $foo1, Foo $foo2) { return $foo2->hasGreaterAThan($foo1); }; assert($find_by($list, $greaterA) === $foo2); assert($find_by($list, $lesserA) === $foo3);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6O94O
function name:  (null)
number of ops:  43
compiled vars:  !0 = $list, !1 = $foo1, !2 = $foo2, !3 = $foo3, !4 = $find_by, !5 = $greaterA, !6 = $lesserA
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   NEW                                              $7      'Foo'
          1        SEND_VAL_EX                                              2
          2        DO_FCALL                                      0          
          3        ASSIGN                                           ~9      !1, $7
          4        INIT_ARRAY                                       ~10     ~9
   22     5        NEW                                              $11     'Foo'
          6        SEND_VAL_EX                                              5
          7        DO_FCALL                                      0          
          8        ASSIGN                                           ~13     !2, $11
          9        ADD_ARRAY_ELEMENT                                ~10     ~13
   23    10        NEW                                              $14     'Foo'
         11        SEND_VAL_EX                                              1
         12        DO_FCALL                                      0          
         13        ASSIGN                                           ~16     !3, $14
         14        ADD_ARRAY_ELEMENT                                ~10     ~16
   20    15        ASSIGN                                                   !0, ~10
   34    16        DECLARE_LAMBDA_FUNCTION                          ~18     [0]
         17        ASSIGN                                                   !4, ~18
   41    18        DECLARE_LAMBDA_FUNCTION                          ~20     [1]
         19        ASSIGN                                                   !5, ~20
   45    20        DECLARE_LAMBDA_FUNCTION                          ~22     [2]
         21        ASSIGN                                                   !6, ~22
   50    22        ASSERT_CHECK                                             
         23        INIT_FCALL                                               'assert'
         24        INIT_DYNAMIC_CALL                                        !4
         25        SEND_VAR_EX                                              !0
         26        SEND_VAR_EX                                              !5
         27        DO_FCALL                                      0  $24     
         28        IS_IDENTICAL                                     ~25     !2, $24
         29        SEND_VAL                                                 ~25
         30        SEND_VAL                                                 'assert%28%24find_by%28%24list%2C+%24greaterA%29+%3D%3D%3D+%24foo2%29'
         31        DO_ICALL                                                 
   51    32        ASSERT_CHECK                                             
         33        INIT_FCALL                                               'assert'
         34        INIT_DYNAMIC_CALL                                        !4
         35        SEND_VAR_EX                                              !0
         36        SEND_VAR_EX                                              !6
         37        DO_FCALL                                      0  $27     
         38        IS_IDENTICAL                                     ~28     !3, $27
         39        SEND_VAL                                                 ~28
         40        SEND_VAL                                                 'assert%28%24find_by%28%24list%2C+%24lesserA%29+%3D%3D%3D+%24foo3%29'
         41        DO_ICALL                                                 
         42      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6O94O
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $aList, !1 = $comparison, !2 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   35     2        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          3        BIND_LEXICAL                                             ~3, !1
          4        ASSIGN                                                   !2, ~3
   38     5        INIT_FCALL                                               'array_reduce'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $5      
          9      > RETURN                                                   $5
   39    10*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
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/6O94O
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $carry, !1 = $item, !2 = $comparison
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   36     3        IS_EQUAL                                         ~3      !0, null
          4      > JMPNZ_EX                                         ~3      ~3, ->10
          5    >   INIT_DYNAMIC_CALL                                        !2
          6        SEND_VAR_EX                                              !1
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $4      
          9        BOOL                                             ~3      $4
         10    > > JMPZ                                                     ~3, ->13
         11    >   QM_ASSIGN                                        ~5      !1
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~5      !0
         14    > > RETURN                                                   ~5
   37    15*     > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6O94O
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $foo1, !1 = $foo2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   42     2        INIT_METHOD_CALL                                         !0, 'hasGreaterAThan'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   43     6*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6O94O
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $foo1, !1 = $foo2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   46     2        INIT_METHOD_CALL                                         !1, 'hasGreaterAThan'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   47     6*     > RETURN                                                   null

End of Dynamic Function 2

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

End of function __construct

Function hasgreaterathan:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6O94O
function name:  hasGreaterAThan
number of ops:  6
compiled vars:  !0 = $another
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        FETCH_OBJ_R                                      ~1      'a'
          2        FETCH_OBJ_R                                      ~2      !0, 'a'
          3        IS_SMALLER                                       ~3      ~2, ~1
          4      > RETURN                                                   ~3
   17     5*     > RETURN                                                   null

End of function hasgreaterathan

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
268.95 ms | 1012 KiB | 15 Q