3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); class BinarySearch { /** * @param mixed[] $items */ public function __invoke(array $items): int { for ($start = 0, $end = count($items); $i = $start + (int) (($end - $start) / 2), $i < $end; ) { // do something here break; } return $i; } } $binarySearch = new BinarySearch(); var_dump($binarySearch([])); var_dump($binarySearch([0, 1, 2, 3])); var_dump($binarySearch([0, 1, 2, 3, 4, 5, 6])); var_dump($binarySearch([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LVt1P
function name:  (null)
number of ops:  28
compiled vars:  !0 = $binarySearch
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   NEW                                              $1      'BinarySearch'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   23     3        INIT_FCALL                                               'var_dump'
          4        INIT_DYNAMIC_CALL                                        !0
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   24     9        INIT_FCALL                                               'var_dump'
         10        INIT_DYNAMIC_CALL                                        !0
         11        SEND_VAL_EX                                              <array>
         12        DO_FCALL                                      0  $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                                 
   25    15        INIT_FCALL                                               'var_dump'
         16        INIT_DYNAMIC_CALL                                        !0
         17        SEND_VAL_EX                                              <array>
         18        DO_FCALL                                      0  $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                                 
   26    21        INIT_FCALL                                               'var_dump'
         22        INIT_DYNAMIC_CALL                                        !0
         23        SEND_VAL_EX                                              <array>
         24        DO_FCALL                                      0  $10     
         25        SEND_VAR                                                 $10
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Class BinarySearch:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 5
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
filename:       /in/LVt1P
function name:  __invoke
number of ops:  17
compiled vars:  !0 = $items, !1 = $start, !2 = $end, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        ASSIGN                                                   !1, 0
          2        COUNT                                            ~5      !0
          3        ASSIGN                                                   !2, ~5
          4      > JMP                                                      ->6
   14     5    > > JMP                                                      ->13
   11     6    >   SUB                                              ~7      !2, !1
          7        DIV                                              ~8      ~7, 2
          8        CAST                                          4  ~9      ~8
          9        ADD                                              ~10     !1, ~9
         10        ASSIGN                                                   !3, ~10
         11        IS_SMALLER                                               !3, !2
         12      > JMPNZ                                                    ~12, ->5
   17    13    >   VERIFY_RETURN_TYPE                                       !3
         14      > RETURN                                                   !3
   18    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null

End of function __invoke

End of class BinarySearch.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
214.06 ms | 1092 KiB | 14 Q