3v4l.org

run code in 500+ PHP versions simultaneously
<?php function open_closed_message() { date_default_timezone_set('America/Toronto'); $date = new DateTime; echo date("D m/d/y h:i:s ",time()); $times = array( 'mon' => '9:00 AM - 9:00 PM', 'tue' => '9:00 AM - 9:00 PM', 'wed' => '9:00 AM - 9:00 PM', 'thu' => '9:00 AM - 9:00 PM', 'fri' => '9:00 AM - 9:00 PM', 'sat' => '11:00 AM - 6:00 PM', 'sun' => 'closed' ); function compileHours($times, $timestamp) { $times = $times[strtolower(date('D',$timestamp))]; if(!strpos($times, '-')) return array(); $hours = explode(",", $times); $hours = array_map('explode', array_pad(array(),count($hours),'-'), $hours); $hours = array_map('array_map', array_pad(array(),count($hours),'strtotime'), $hours, array_pad(array(),count($hours),array_pad(array(),2,$timestamp))); end($hours); if ($hours[key($hours)][0] > $hours[key($hours)][1]) $hours[key($hours)][1] = strtotime('+1 day', $hours[key($hours)][1]); return $hours; } function isOpen($now, $times) { $open = 0; // time until closing in seconds or 0 if closed // merge opening hours of today and the day before $hours = array_merge(compileHours($times, strtotime('yesterday',$now)),compileHours($times, $now)); foreach ($hours as $h) { if ($now >= $h[0] and $now < $h[1]) { $open = $h[1] - $now; return $open; } } return $open; } $now = time(); $open = isOpen($now, $times); if ($open == 0) { echo "Closed - Sorry, we are not making deliveries."; } elseif ($open <= 1800) { $tomorrow = strtotime('tomorrow', $now); if (date('N', $tomorrow) == 7) { $tomorrow = strtotime('next monday', $now); } $day = strtolower(date('D', $tomorrow)); $tomorrow = date('l', $tomorrow); $opentime = preg_replace('/^(\d+:\d+ [AP]M).*/', '$1', $times[$day]); echo "Finishing up current orders. We re-open $tomorrow at $opentime"; } else { echo "Open - Yes, we are making deliveries."; } } open_closed_message();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0ABL6
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   65     0  E >   INIT_FCALL                                                   'open_closed_message'
          1        DO_FCALL                                          0          
          2      > RETURN                                                       1

Function open_closed_message:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 69
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 46
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0ABL6
function name:  open_closed_message
number of ops:  71
compiled vars:  !0 = $date, !1 = $times, !2 = $now, !3 = $open, !4 = $tomorrow, !5 = $day, !6 = $opentime
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                                   'date_default_timezone_set'
          1        SEND_VAL                                                     'America%2FToronto'
          2        DO_ICALL                                                     
    6     3        NEW                                                  $8      'DateTime'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !0, $8
    7     6        INIT_FCALL                                                   'date'
          7        SEND_VAL                                                     'D+m%2Fd%2Fy++h%3Ai%3As+'
          8        INIT_FCALL                                                   'time'
          9        DO_ICALL                                             $11     
         10        SEND_VAR                                                     $11
         11        DO_ICALL                                             $12     
         12        ECHO                                                         $12
    9    13        ASSIGN                                                       !1, <array>
   19    14        DECLARE_FUNCTION                                             'compilehours'
   30    15        DECLARE_FUNCTION                                             'isopen'
   44    16        INIT_FCALL                                                   'time'
         17        DO_ICALL                                             $14     
         18        ASSIGN                                                       !2, $14
   45    19        INIT_FCALL_BY_NAME                                           'isOpen'
         20        SEND_VAR_EX                                                  !2
         21        SEND_VAR_EX                                                  !1
         22        DO_FCALL                                          0  $16     
         23        ASSIGN                                                       !3, $16
   47    24        IS_EQUAL                                                     !3, 0
         25      > JMPZ                                                         ~18, ->28
   48    26    >   ECHO                                                         'Closed+-+Sorry%2C+we+are+not+making+deliveries.'
   47    27      > JMP                                                          ->70
   50    28    >   IS_SMALLER_OR_EQUAL                                          !3, 1800
         29      > JMPZ                                                         ~19, ->69
   51    30    >   INIT_FCALL                                                   'strtotime'
         31        SEND_VAL                                                     'tomorrow'
         32        SEND_VAR                                                     !2
         33        DO_ICALL                                             $20     
         34        ASSIGN                                                       !4, $20
   52    35        INIT_FCALL                                                   'date'
         36        SEND_VAL                                                     'N'
         37        SEND_VAR                                                     !4
         38        DO_ICALL                                             $22     
         39        IS_EQUAL                                                     $22, 7
         40      > JMPZ                                                         ~23, ->46
   53    41    >   INIT_FCALL                                                   'strtotime'
         42        SEND_VAL                                                     'next+monday'
         43        SEND_VAR                                                     !2
         44        DO_ICALL                                             $24     
         45        ASSIGN                                                       !4, $24
   55    46    >   INIT_FCALL                                                   'strtolower'
         47        INIT_FCALL                                                   'date'
         48        SEND_VAL                                                     'D'
         49        SEND_VAR                                                     !4
         50        DO_ICALL                                             $26     
         51        SEND_VAR                                                     $26
         52        DO_ICALL                                             $27     
         53        ASSIGN                                                       !5, $27
   56    54        INIT_FCALL                                                   'date'
         55        SEND_VAL                                                     'l'
         56        SEND_VAR                                                     !4
         57        DO_ICALL                                             $29     
         58        ASSIGN                                                       !4, $29
   57    59        FETCH_DIM_R                                          ~31     !1, !5
         60        FRAMELESS_ICALL_3                preg_replace        ~32     '%2F%5E%28%5Cd%2B%3A%5Cd%2B+%5BAP%5DM%29.%2A%2F', '%241'
         61        OP_DATA                                                      ~31
         62        ASSIGN                                                       !6, ~32
   58    63        ROPE_INIT                                         4  ~35     'Finishing+up+current+orders.+We+re-open+'
         64        ROPE_ADD                                          1  ~35     ~35, !4
         65        ROPE_ADD                                          2  ~35     ~35, '+at+'
         66        ROPE_END                                          3  ~34     ~35, !6
         67        ECHO                                                         ~34
   50    68      > JMP                                                          ->70
   61    69    >   ECHO                                                         'Open+-+Yes%2C+we+are+making+deliveries.'
   63    70    > > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 86
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 86
filename:       /in/0ABL6
function name:  compileHours
number of ops:  88
compiled vars:  !0 = $times, !1 = $timestamp, !2 = $hours
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   20     2        INIT_FCALL                                                   'strtolower'
          3        INIT_FCALL                                                   'date'
          4        SEND_VAL                                                     'D'
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $3      
          7        SEND_VAR                                                     $3
          8        DO_ICALL                                             $4      
          9        FETCH_DIM_R                                          ~5      !0, $4
         10        ASSIGN                                                       !0, ~5
   21    11        FRAMELESS_ICALL_2                strpos              ~7      !0, '-'
         12        BOOL_NOT                                             ~8      ~7
         13      > JMPZ                                                         ~8, ->15
         14    > > RETURN                                                       <array>
   22    15    >   INIT_FCALL                                                   'explode'
         16        SEND_VAL                                                     '%2C'
         17        SEND_VAR                                                     !0
         18        DO_ICALL                                             $9      
         19        ASSIGN                                                       !2, $9
   23    20        INIT_FCALL                                                   'array_map'
         21        SEND_VAL                                                     'explode'
         22        INIT_FCALL                                                   'array_pad'
         23        SEND_VAL                                                     <array>
         24        COUNT                                                ~11     !2
         25        SEND_VAL                                                     ~11
         26        SEND_VAL                                                     '-'
         27        DO_ICALL                                             $12     
         28        SEND_VAR                                                     $12
         29        SEND_VAR                                                     !2
         30        DO_ICALL                                             $13     
         31        ASSIGN                                                       !2, $13
   24    32        INIT_FCALL                                                   'array_map'
         33        SEND_VAL                                                     'array_map'
         34        INIT_FCALL                                                   'array_pad'
         35        SEND_VAL                                                     <array>
         36        COUNT                                                ~15     !2
         37        SEND_VAL                                                     ~15
         38        SEND_VAL                                                     'strtotime'
         39        DO_ICALL                                             $16     
         40        SEND_VAR                                                     $16
         41        SEND_VAR                                                     !2
         42        INIT_FCALL                                                   'array_pad'
         43        SEND_VAL                                                     <array>
         44        COUNT                                                ~17     !2
         45        SEND_VAL                                                     ~17
         46        INIT_FCALL                                                   'array_pad'
         47        SEND_VAL                                                     <array>
         48        SEND_VAL                                                     2
         49        SEND_VAR                                                     !1
         50        DO_ICALL                                             $18     
         51        SEND_VAR                                                     $18
         52        DO_ICALL                                             $19     
         53        SEND_VAR                                                     $19
         54        DO_ICALL                                             $20     
         55        ASSIGN                                                       !2, $20
   25    56        INIT_FCALL                                                   'end'
         57        SEND_REF                                                     !2
         58        DO_ICALL                                                     
   26    59        INIT_FCALL                                                   'key'
         60        SEND_VAR                                                     !2
         61        DO_ICALL                                             $23     
         62        FETCH_DIM_R                                          ~24     !2, $23
         63        FETCH_DIM_R                                          ~25     ~24, 0
         64        INIT_FCALL                                                   'key'
         65        SEND_VAR                                                     !2
         66        DO_ICALL                                             $26     
         67        FETCH_DIM_R                                          ~27     !2, $26
         68        FETCH_DIM_R                                          ~28     ~27, 1
         69        IS_SMALLER                                                   ~28, ~25
         70      > JMPZ                                                         ~29, ->86
         71    >   INIT_FCALL                                                   'key'
         72        SEND_VAR                                                     !2
         73        DO_ICALL                                             $30     
         74        INIT_FCALL                                                   'strtotime'
         75        SEND_VAL                                                     '%2B1+day'
         76        INIT_FCALL                                                   'key'
         77        SEND_VAR                                                     !2
         78        DO_ICALL                                             $33     
         79        FETCH_DIM_R                                          ~34     !2, $33
         80        FETCH_DIM_R                                          ~35     ~34, 1
         81        SEND_VAL                                                     ~35
         82        DO_ICALL                                             $36     
         83        FETCH_DIM_W                                          $31     !2, $30
         84        ASSIGN_DIM                                                   $31, 1
         85        OP_DATA                                                      $36
   27    86    > > RETURN                                                       !2
   28    87*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 35
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 35
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 28
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/0ABL6
function name:  isOpen
number of ops:  38
compiled vars:  !0 = $now, !1 = $times, !2 = $open, !3 = $hours, !4 = $h
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   31     2        ASSIGN                                                       !2, 0
   33     3        INIT_FCALL                                                   'array_merge'
          4        INIT_FCALL_BY_NAME                                           'compileHours'
          5        SEND_VAR_EX                                                  !1
          6        INIT_FCALL                                                   'strtotime'
          7        SEND_VAL                                                     'yesterday'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $6      
         10        SEND_VAR_NO_REF_EX                                           $6
         11        DO_FCALL                                          0  $7      
         12        SEND_VAR                                                     $7
         13        INIT_FCALL_BY_NAME                                           'compileHours'
         14        SEND_VAR_EX                                                  !1
         15        SEND_VAR_EX                                                  !0
         16        DO_FCALL                                          0  $8      
         17        SEND_VAR                                                     $8
         18        DO_ICALL                                             $9      
         19        ASSIGN                                                       !3, $9
   35    20      > FE_RESET_R                                           $11     !3, ->35
         21    > > FE_FETCH_R                                                   $11, !4, ->35
   36    22    >   FETCH_DIM_R                                          ~12     !4, 0
         23        IS_SMALLER_OR_EQUAL                                  ~13     ~12, !0
         24      > JMPZ_EX                                              ~13     ~13, ->28
         25    >   FETCH_DIM_R                                          ~14     !4, 1
         26        IS_SMALLER                                           ~15     !0, ~14
         27        BOOL                                                 ~13     ~15
         28    > > JMPZ                                                         ~13, ->34
   37    29    >   FETCH_DIM_R                                          ~16     !4, 1
         30        SUB                                                  ~17     ~16, !0
         31        ASSIGN                                                       !2, ~17
   38    32        FE_FREE                                                      $11
         33      > RETURN                                                       !2
   35    34    > > JMP                                                          ->21
         35    >   FE_FREE                                                      $11
   41    36      > RETURN                                                       !2
   42    37*     > RETURN                                                       null

End of Dynamic Function 1

End of function open_closed_message

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
135.42 ms | 512 KiB | 19 Q