3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setting($v) { $db = [ 'opening_time_Sunday' => '10:30', 'closing_time_Sunday' => '00:00', 'opening_time_Monday' => '09:30', 'closing_time_Monday' => '01:30', 'opening_time_Tuesday' => '09:30', 'closing_time_Tuesday' => '01:30', 'opening_time_Wednesday' => '09:30', 'closing_time_Wednesday' => '01:30', 'opening_time_Thursday' => '09:30', 'closing_time_Thursday' => '01:30', 'opening_time_Friday' => '09:30', 'closing_time_Friday' => '23:00', 'opening_time_Saturday' => '10:30', 'closing_time_Saturday' => '00:00', ]; return $db[$v]; } function Today($dateString = null) { $currentDate = new \DateTimeImmutable($dateString); $priorDate = $currentDate->sub(new \DateInterval('P1D')); $yesterday = $priorDate->format('l'); $priorOpening = setting('opening_time_' . $yesterday); $priorClosing = setting('closing_time_' . $yesterday); $priorOpenDate = $priorDate->setTime(...explode(':', $priorOpening)); $closeDate = $currentDate->setTime(...explode(':', $priorClosing)); $diff = $priorOpenDate->diff($closeDate); if ($diff->d === 0 && $currentDate < $closeDate) { //check if the closing has not occurred yet $currentDate = $priorDate; } $today = $currentDate->format('l'); $start = setting('opening_time_' . $today); $end = setting('closing_time_' . $today); return $today . ': ' . $start . " - " . $end; } $dates = []; for ($i=0;$i<7;$i++) { $date = \date_create('2018-10-08'); if ($i > 0) { $date->modify('+' . $i . ' day'); } $dates[$date->format('l')] = [ '00:15' => Today($date->setTime(0, 15)->format('Y-m-d H:i:s')), '23:00' => Today($date->setTime(23, 0, 0)->format('Y-m-d H:i:s')) ]; } echo "Day \t|\t00:15:00\t\t\t|\t23:00:00\n"; foreach($dates as $day => $times) { echo "$day \t|\t{$times['00:15']} \t|\t{$times['23:00']}\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 3
Branch analysis from position: 45
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 59
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 59
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 3
Branch analysis from position: 45
Branch analysis from position: 3
Branch analysis from position: 14
filename:       /in/q57eD
function name:  (null)
number of ops:  61
compiled vars:  !0 = $dates, !1 = $i, !2 = $date, !3 = $times, !4 = $day
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   ASSIGN                                                   !0, <array>
   54     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->43
   55     3    >   INIT_FCALL                                               'date_create'
          4        SEND_VAL                                                 '2018-10-08'
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !2, $7
   56     7        IS_SMALLER                                               0, !1
          8      > JMPZ                                                     ~9, ->14
   57     9    >   INIT_METHOD_CALL                                         !2, 'modify'
         10        CONCAT                                           ~10     '%2B', !1
         11        CONCAT                                           ~11     ~10, '+day'
         12        SEND_VAL_EX                                              ~11
         13        DO_FCALL                                      0          
   59    14    >   INIT_METHOD_CALL                                         !2, 'format'
         15        SEND_VAL_EX                                              'l'
         16        DO_FCALL                                      0  $13     
   60    17        INIT_FCALL                                               'today'
         18        INIT_METHOD_CALL                                         !2, 'setTime'
         19        SEND_VAL_EX                                              0
         20        SEND_VAL_EX                                              15
         21        DO_FCALL                                      0  $15     
         22        INIT_METHOD_CALL                                         $15, 'format'
         23        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         24        DO_FCALL                                      0  $16     
         25        SEND_VAR                                                 $16
         26        DO_FCALL                                      0  $17     
         27        INIT_ARRAY                                       ~18     $17, '00%3A15'
   61    28        INIT_FCALL                                               'today'
         29        INIT_METHOD_CALL                                         !2, 'setTime'
         30        SEND_VAL_EX                                              23
         31        SEND_VAL_EX                                              0
         32        SEND_VAL_EX                                              0
         33        DO_FCALL                                      0  $19     
         34        INIT_METHOD_CALL                                         $19, 'format'
         35        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         36        DO_FCALL                                      0  $20     
         37        SEND_VAR                                                 $20
         38        DO_FCALL                                      0  $21     
         39        ADD_ARRAY_ELEMENT                                ~18     $21, '23%3A00'
   59    40        ASSIGN_DIM                                               !0, $13
   61    41        OP_DATA                                                  ~18
   54    42        PRE_INC                                                  !1
         43    >   IS_SMALLER                                               !1, 7
         44      > JMPNZ                                                    ~23, ->3
   64    45    >   ECHO                                                     'Day+++++++++%09%7C%0900%3A15%3A00%09%09%09%7C%0923%3A00%3A00%0A'
   65    46      > FE_RESET_R                                       $24     !0, ->59
         47    > > FE_FETCH_R                                       ~25     $24, !3, ->59
         48    >   ASSIGN                                                   !4, ~25
   66    49        ROPE_INIT                                     6  ~30     !4
         50        ROPE_ADD                                      1  ~30     ~30, '++%09%7C%09'
         51        FETCH_DIM_R                                      ~27     !3, '00%3A15'
         52        ROPE_ADD                                      2  ~30     ~30, ~27
         53        ROPE_ADD                                      3  ~30     ~30, '++++%09%7C%09'
         54        FETCH_DIM_R                                      ~28     !3, '23%3A00'
         55        ROPE_ADD                                      4  ~30     ~30, ~28
         56        ROPE_END                                      5  ~29     ~30, '%0A'
         57        ECHO                                                     ~29
   65    58      > JMP                                                      ->47
         59    >   FE_FREE                                                  $24
   67    60      > RETURN                                                   1

Function setting:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q57eD
function name:  setting
number of ops:  5
compiled vars:  !0 = $v, !1 = $db
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   22     2        FETCH_DIM_R                                      ~3      !1, !0
          3      > RETURN                                                   ~3
   24     4*     > RETURN                                                   null

End of function setting

Function today:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 51, Position 2 = 53
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 55
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 53
filename:       /in/q57eD
function name:  Today
number of ops:  75
compiled vars:  !0 = $dateString, !1 = $currentDate, !2 = $priorDate, !3 = $yesterday, !4 = $priorOpening, !5 = $priorClosing, !6 = $priorOpenDate, !7 = $closeDate, !8 = $diff, !9 = $today, !10 = $start, !11 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV_INIT                                        !0      null
   28     1        NEW                                              $12     'DateTimeImmutable'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $12
   30     5        INIT_METHOD_CALL                                         !1, 'sub'
          6        NEW                                              $15     'DateInterval'
          7        SEND_VAL_EX                                              'P1D'
          8        DO_FCALL                                      0          
          9        SEND_VAR_NO_REF_EX                                       $15
         10        DO_FCALL                                      0  $17     
         11        ASSIGN                                                   !2, $17
   31    12        INIT_METHOD_CALL                                         !2, 'format'
         13        SEND_VAL_EX                                              'l'
         14        DO_FCALL                                      0  $19     
         15        ASSIGN                                                   !3, $19
   33    16        INIT_FCALL                                               'setting'
         17        CONCAT                                           ~21     'opening_time_', !3
         18        SEND_VAL                                                 ~21
         19        DO_FCALL                                      0  $22     
         20        ASSIGN                                                   !4, $22
   34    21        INIT_FCALL                                               'setting'
         22        CONCAT                                           ~24     'closing_time_', !3
         23        SEND_VAL                                                 ~24
         24        DO_FCALL                                      0  $25     
         25        ASSIGN                                                   !5, $25
   36    26        INIT_METHOD_CALL                                         !2, 'setTime'
         27        INIT_FCALL                                               'explode'
         28        SEND_VAL                                                 '%3A'
         29        SEND_VAR                                                 !4
         30        DO_ICALL                                         $27     
         31        SEND_UNPACK                                              $27
         32        CHECK_UNDEF_ARGS                                         
         33        DO_FCALL                                      1  $28     
         34        ASSIGN                                                   !6, $28
   37    35        INIT_METHOD_CALL                                         !1, 'setTime'
         36        INIT_FCALL                                               'explode'
         37        SEND_VAL                                                 '%3A'
         38        SEND_VAR                                                 !5
         39        DO_ICALL                                         $30     
         40        SEND_UNPACK                                              $30
         41        CHECK_UNDEF_ARGS                                         
         42        DO_FCALL                                      1  $31     
         43        ASSIGN                                                   !7, $31
   38    44        INIT_METHOD_CALL                                         !6, 'diff'
         45        SEND_VAR_EX                                              !7
         46        DO_FCALL                                      0  $33     
         47        ASSIGN                                                   !8, $33
   40    48        FETCH_OBJ_R                                      ~35     !8, 'd'
         49        IS_IDENTICAL                                     ~36     ~35, 0
         50      > JMPZ_EX                                          ~36     ~36, ->53
         51    >   IS_SMALLER                                       ~37     !1, !7
         52        BOOL                                             ~36     ~37
         53    > > JMPZ                                                     ~36, ->55
   42    54    >   ASSIGN                                                   !1, !2
   46    55    >   INIT_METHOD_CALL                                         !1, 'format'
         56        SEND_VAL_EX                                              'l'
         57        DO_FCALL                                      0  $39     
         58        ASSIGN                                                   !9, $39
   47    59        INIT_FCALL                                               'setting'
         60        CONCAT                                           ~41     'opening_time_', !9
         61        SEND_VAL                                                 ~41
         62        DO_FCALL                                      0  $42     
         63        ASSIGN                                                   !10, $42
   48    64        INIT_FCALL                                               'setting'
         65        CONCAT                                           ~44     'closing_time_', !9
         66        SEND_VAL                                                 ~44
         67        DO_FCALL                                      0  $45     
         68        ASSIGN                                                   !11, $45
   50    69        CONCAT                                           ~47     !9, '%3A+'
         70        CONCAT                                           ~48     ~47, !10
         71        CONCAT                                           ~49     ~48, '+-+'
         72        CONCAT                                           ~50     ~49, !11
         73      > RETURN                                                   ~50
   51    74*     > RETURN                                                   null

End of function today

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
289.18 ms | 1027 KiB | 21 Q