3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vacancies = [ '2024-01-01 09:00:00' => 'booked', '2024-01-01 09:10:00' => 'booked', '2024-01-01 09:20:00' => 'booked', '2024-01-01 09:30:00' => 'booked', '2024-01-01 09:40:00' => 'booked', '2024-01-01 09:50:00' => 'booked', '2024-01-01 10:00:00' => null, '2024-01-01 10:10:00' => null, '2024-01-01 10:20:00' => null, '2024-01-01 10:30:00' => null, '2024-01-01 10:40:00' => null, '2024-01-01 10:50:00' => null, '2024-01-01 11:00:00' => null, '2024-01-01 11:10:00' => null, '2024-01-01 11:20:00' => null, '2024-01-01 11:30:00' => null, '2024-01-01 11:40:00' => null, '2024-01-01 11:50:00' => null, '2024-01-01 12:00:00' => null, '2024-01-01 12:10:00' => null, '2024-01-01 12:20:00' => null, '2024-01-01 12:30:00' => null, '2024-01-01 12:40:00' => null, '2024-01-01 12:50:00' => null, '2024-01-01 13:00:00' => null, '2024-01-01 13:10:00' => null, '2024-01-01 13:20:00' => null, '2024-01-01 13:30:00' => null, '2024-01-01 13:40:00' => null, '2024-01-01 13:50:00' => null, '2024-01-01 14:00:00' => null, '2024-01-01 14:10:00' => null, '2024-01-01 14:20:00' => null, '2024-01-01 14:30:00' => null, '2024-01-01 14:40:00' => null, '2024-01-01 14:50:00' => null, '2024-01-01 15:00:00' => null, '2024-01-01 15:10:00' => null, '2024-01-01 15:20:00' => null, '2024-01-01 15:30:00' => null, '2024-01-01 15:40:00' => null, '2024-01-01 15:50:00' => null, '2024-01-01 16:00:00' => 'booked', '2024-01-01 16:10:00' => 'booked', '2024-01-01 16:20:00' => 'booked', '2024-01-01 16:30:00' => 'booked', '2024-01-01 16:40:00' => 'booked', '2024-01-01 16:50:00' => null, '2024-01-01 17:00:00' => null, '2024-01-01 17:10:00' => null, '2024-01-01 17:20:00' => null, '2024-01-01 17:30:00' => null, '2024-01-01 17:40:00' => null, '2024-01-01 17:50:00' => null, ]; $newTests = [ '2024-01-01 09:50:00', '2024-01-01 10:00:00', '2024-01-01 15:40:00', '2024-01-01 17:40:00', ]; function is30MinuteSessionVacant(array $vacancies, string $dateTime): bool { for ($addMinutes = 0; $addMinutes < 30; $addMinutes += 10) { $dateTime = date('Y-m-d H:i:s', strtotime("$dateTime +{$addMinutes} minutes")); if (!key_exists($dateTime, $vacancies)) { throw new Exception('Proposed time is not within business hours'); } if ($vacancies[$dateTime] !== null) { return false; } } return true; } foreach ($newTests as $test) { echo "\n$test: "; try { echo is30MinuteSessionVacant($vacancies, $test) ? 'available' : 'unavailable'; } catch (Exception $e) { echo $e->getMessage(); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 23
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Found catch point at position: 18
Branch analysis from position: 18
2 jumps found. (Code = 107) Position 1 = 19, Position 2 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
filename:       /in/iQ20h
function name:  (null)
number of ops:  25
compiled vars:  !0 = $vacancies, !1 = $newTests, !2 = $test, !3 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   60     1        ASSIGN                                                   !1, <array>
   81     2      > FE_RESET_R                                       $6      !1, ->23
          3    > > FE_FETCH_R                                               $6, !2, ->23
   82     4    >   ROPE_INIT                                     3  ~8      '%0A'
          5        ROPE_ADD                                      1  ~8      ~8, !2
          6        ROPE_END                                      2  ~7      ~8, '%3A+'
          7        ECHO                                                     ~7
   84     8        INIT_FCALL                                               'is30minutesessionvacant'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !2
         11        DO_FCALL                                      0  $10     
         12      > JMPZ                                                     $10, ->15
         13    >   QM_ASSIGN                                        ~11     'available'
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~11     'unavailable'
         16    >   ECHO                                                     ~11
         17      > JMP                                                      ->22
   85    18  E > > CATCH                                       last         'Exception'
   86    19    >   INIT_METHOD_CALL                                         !3, 'getMessage'
         20        DO_FCALL                                      0  $12     
         21        ECHO                                                     $12
   81    22    > > JMP                                                      ->3
         23    >   FE_FREE                                                  $6
   88    24      > RETURN                                                   1

Function is30minutesessionvacant:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 4
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 4
Branch analysis from position: 33
Branch analysis from position: 4
filename:       /in/iQ20h
function name:  is30MinuteSessionVacant
number of ops:  36
compiled vars:  !0 = $vacancies, !1 = $dateTime, !2 = $addMinutes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   69     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->31
   70     4    >   INIT_FCALL                                               'date'
          5        SEND_VAL                                                 'Y-m-d+H%3Ai%3As'
          6        INIT_FCALL                                               'strtotime'
          7        ROPE_INIT                                     4  ~5      !1
          8        ROPE_ADD                                      1  ~5      ~5, '+%2B'
          9        ROPE_ADD                                      2  ~5      ~5, !2
         10        ROPE_END                                      3  ~4      ~5, '+minutes'
         11        SEND_VAL                                                 ~4
         12        DO_ICALL                                         $7      
         13        SEND_VAR                                                 $7
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !1, $8
   71    16        INIT_FCALL                                               'key_exists'
         17        SEND_VAR                                                 !1
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $10     
         20        BOOL_NOT                                         ~11     $10
         21      > JMPZ                                                     ~11, ->26
   72    22    >   NEW                                              $12     'Exception'
         23        SEND_VAL_EX                                              'Proposed+time+is+not+within+business+hours'
         24        DO_FCALL                                      0          
         25      > THROW                                         0          $12
   74    26    >   FETCH_DIM_R                                      ~14     !0, !1
         27        TYPE_CHECK                                  1020          ~14
         28      > JMPZ                                                     ~15, ->30
   75    29    > > RETURN                                                   <false>
   69    30    >   ASSIGN_OP                                     1          !2, 10
         31    >   IS_SMALLER                                               !2, 30
         32      > JMPNZ                                                    ~17, ->4
   78    33    > > RETURN                                                   <true>
   79    34*       VERIFY_RETURN_TYPE                                       
         35*     > RETURN                                                   null

End of function is30minutesessionvacant

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.76 ms | 1007 KiB | 17 Q