3v4l.org

run code in 300+ 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 = 73
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 72
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 = 73
Branch analysis from position: 73
Branch analysis from position: 46
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0ABL6
function name:  open_closed_message
number of ops:  74
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.'
         27      > JMP                                                      ->73
   50    28    >   IS_SMALLER_OR_EQUAL                                      !3, 1800
         29      > JMPZ                                                     ~19, ->72
   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        INIT_FCALL                                               'preg_replace'
         60        SEND_VAL                                                 '%2F%5E%28%5Cd%2B%3A%5Cd%2B+%5BAP%5DM%29.%2A%2F'
         61        SEND_VAL                                                 '%241'
         62        FETCH_DIM_R                                      ~31     !1, !5
         63        SEND_VAL                                                 ~31
         64        DO_ICALL                                         $32     
         65        ASSIGN                                                   !6, $32
   58    66        ROPE_INIT                                     4  ~35     'Finishing+up+current+orders.+We+re-open+'
         67        ROPE_ADD                                      1  ~35     ~35, !4
         68        ROPE_ADD                                      2  ~35     ~35, '+at+'
         69        ROPE_END                                      3  ~34     ~35, !6
         70        ECHO                                                     ~34
         71      > JMP                                                      ->73
   61    72    >   ECHO                                                     'Open+-+Yes%2C+we+are+making+deliveries.'
   63    73    > > RETURN                                                   null

End of function open_closed_message

Function %00compilehours%2Fin%2F0ABL6%3A19%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 89
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 89
filename:       /in/0ABL6
function name:  compileHours
number of ops:  91
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        INIT_FCALL                                               'strpos'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 '-'
         14        DO_ICALL                                         $7      
         15        BOOL_NOT                                         ~8      $7
         16      > JMPZ                                                     ~8, ->18
         17    > > RETURN                                                   <array>
   22    18    >   INIT_FCALL                                               'explode'
         19        SEND_VAL                                                 '%2C'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $9      
         22        ASSIGN                                                   !2, $9
   23    23        INIT_FCALL                                               'array_map'
         24        SEND_VAL                                                 'explode'
         25        INIT_FCALL                                               'array_pad'
         26        SEND_VAL                                                 <array>
         27        COUNT                                            ~11     !2
         28        SEND_VAL                                                 ~11
         29        SEND_VAL                                                 '-'
         30        DO_ICALL                                         $12     
         31        SEND_VAR                                                 $12
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                         $13     
         34        ASSIGN                                                   !2, $13
   24    35        INIT_FCALL                                               'array_map'
         36        SEND_VAL                                                 'array_map'
         37        INIT_FCALL                                               'array_pad'
         38        SEND_VAL                                                 <array>
         39        COUNT                                            ~15     !2
         40        SEND_VAL                                                 ~15
         41        SEND_VAL                                                 'strtotime'
         42        DO_ICALL                                         $16     
         43        SEND_VAR                                                 $16
         44        SEND_VAR                                                 !2
         45        INIT_FCALL                                               'array_pad'
         46        SEND_VAL                                                 <array>
         47        COUNT                                            ~17     !2
         48        SEND_VAL                                                 ~17
         49        INIT_FCALL                                               'array_pad'
         50        SEND_VAL                                                 <array>
         51        SEND_VAL                                                 2
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                         $18     
         54        SEND_VAR                                                 $18
         55        DO_ICALL                                         $19     
         56        SEND_VAR                                                 $19
         57        DO_ICALL                                         $20     
         58        ASSIGN                                                   !2, $20
   25    59        INIT_FCALL                                               'end'
         60        SEND_REF                                                 !2
         61        DO_ICALL                                                 
   26    62        INIT_FCALL                                               'key'
         63        SEND_VAR                                                 !2
         64        DO_ICALL                                         $23     
         65        FETCH_DIM_R                                      ~24     !2, $23
         66        FETCH_DIM_R                                      ~25     ~24, 0
         67        INIT_FCALL                                               'key'
         68        SEND_VAR                                                 !2
         69        DO_ICALL                                         $26     
         70        FETCH_DIM_R                                      ~27     !2, $26
         71        FETCH_DIM_R                                      ~28     ~27, 1
         72        IS_SMALLER                                               ~28, ~25
         73      > JMPZ                                                     ~29, ->89
         74    >   INIT_FCALL                                               'key'
         75        SEND_VAR                                                 !2
         76        DO_ICALL                                         $30     
         77        INIT_FCALL                                               'strtotime'
         78        SEND_VAL                                                 '%2B1+day'
         79        INIT_FCALL                                               'key'
         80        SEND_VAR                                                 !2
         81        DO_ICALL                                         $33     
         82        FETCH_DIM_R                                      ~34     !2, $33
         83        FETCH_DIM_R                                      ~35     ~34, 1
         84        SEND_VAL                                                 ~35
         85        DO_ICALL                                         $36     
         86        FETCH_DIM_W                                      $31     !2, $30
         87        ASSIGN_DIM                                               $31, 1
         88        OP_DATA                                                  $36
   27    89    > > RETURN                                                   !2
   28    90*     > RETURN                                                   null

End of function %00compilehours%2Fin%2F0ABL6%3A19%240

Function %00isopen%2Fin%2F0ABL6%3A30%241:
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 function %00isopen%2Fin%2F0ABL6%3A30%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.28 ms | 1419 KiB | 40 Q