3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Person { var $name; var $age; function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $a = new ArrayIterator([ new Person("Christoph", 15), new Person("John", 42), new Person("Foobar", 25) ]); function first_match(\Iterator $iterator, callable $callback) { foreach ($iterator as $key => $value) { if ($callback($value, $key)) { yield $key => $value; break; } } } $firstOver18 = function($person) { return $person->age >= 18; }; foreach (first_match($a, $firstOver18) as $p) { var_dump($p); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/dWOuN
function name:  (null)
number of ops:  33
compiled vars:  !0 = $a, !1 = $firstOver18, !2 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $3      'ArrayIterator'
   16     1        NEW                                              $4      'Person'
          2        SEND_VAL_EX                                              'Christoph'
          3        SEND_VAL_EX                                              15
          4        DO_FCALL                                      0          
          5        INIT_ARRAY                                       ~6      $4
   17     6        NEW                                              $7      'Person'
          7        SEND_VAL_EX                                              'John'
          8        SEND_VAL_EX                                              42
          9        DO_FCALL                                      0          
         10        ADD_ARRAY_ELEMENT                                ~6      $7
   18    11        NEW                                              $9      'Person'
         12        SEND_VAL_EX                                              'Foobar'
         13        SEND_VAL_EX                                              25
         14        DO_FCALL                                      0          
         15        ADD_ARRAY_ELEMENT                                ~6      $9
         16        SEND_VAL_EX                                              ~6
         17        DO_FCALL                                      0          
   15    18        ASSIGN                                                   !0, $3
   31    19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FdWOuN%3A31%240'
         20        ASSIGN                                                   !1, ~13
   36    21        INIT_FCALL                                               'first_match'
         22        SEND_VAR                                                 !0
         23        SEND_VAR                                                 !1
         24        DO_FCALL                                      0  $15     
         25      > FE_RESET_R                                       $16     $15, ->31
         26    > > FE_FETCH_R                                               $16, !2, ->31
   37    27    >   INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                                 
   36    30      > JMP                                                      ->26
         31    >   FE_FREE                                                  $16
   38    32      > RETURN                                                   1

Function first_match:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 14
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 = 161) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
Branch analysis from position: 14
filename:       /in/dWOuN
function name:  first_match
number of ops:  16
compiled vars:  !0 = $iterator, !1 = $callback, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   23     3      > FE_RESET_R                                       $4      !0, ->14
          4    > > FE_FETCH_R                                       ~5      $4, !2, ->14
          5    >   ASSIGN                                                   !3, ~5
   24     6        INIT_DYNAMIC_CALL                                        !1
          7        SEND_VAR_EX                                              !2
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0  $7      
         10      > JMPZ                                                     $7, ->13
   25    11    >   YIELD                                                    !2, !3
   26    12      > JMP                                                      ->14
   23    13    > > JMP                                                      ->4
         14    >   FE_FREE                                                  $4
   29    15      > GENERATOR_RETURN                                         

End of function first_match

Function %00%7Bclosure%7D%2Fin%2FdWOuN%3A31%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dWOuN
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $person
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        FETCH_OBJ_R                                      ~1      !0, 'age'
          2        IS_SMALLER_OR_EQUAL                              ~2      18, ~1
          3      > RETURN                                                   ~2
   33     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FdWOuN%3A31%240

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

End of function __construct

End of class Person.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.29 ms | 1403 KiB | 16 Q