3v4l.org

run code in 300+ PHP versions simultaneously
<?php function period_to_timestamps($period) { switch($period) { case "last_7_days": $start = strtotime('-7 days'); $end = strtotime('now'); break; case "this_month": $start = strtotime('first day of this month'); $end = strtotime('now'); break; case "last_month": $start = strtotime('first day of last month'); $end = strtotime('last day of last month'); break; case "this_year": $start = strtotime('01-01-' . date('Y', strtotime('now'))); $end = strtotime('now'); break; case "last_year": $start = strtotime('01/01/' . date('Y', strtotime('now -1 year'))); $end = strtotime('12/31/' . date('Y', strtotime('now -1 year'))); break; default: $start = strtotime('now'); $end = strtotime('now'); } return array(date('m-d-Y', $start), date('m-d-Y', $end)); } var_dump(period_to_timestamps('last_7_days')); var_dump(period_to_timestamps('this_month')); var_dump(period_to_timestamps('last_month')); var_dump(period_to_timestamps('this_year')); var_dump(period_to_timestamps('last_year'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DfLJ0
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'period_to_timestamps'
          2        SEND_VAL                                                 'last_7_days'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   34     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'period_to_timestamps'
          8        SEND_VAL                                                 'this_month'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
   35    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'period_to_timestamps'
         14        SEND_VAL                                                 'last_month'
         15        DO_FCALL                                      0  $4      
         16        SEND_VAR                                                 $4
         17        DO_ICALL                                                 
   36    18        INIT_FCALL                                               'var_dump'
         19        INIT_FCALL                                               'period_to_timestamps'
         20        SEND_VAL                                                 'this_year'
         21        DO_FCALL                                      0  $6      
         22        SEND_VAR                                                 $6
         23        DO_ICALL                                                 
   37    24        INIT_FCALL                                               'var_dump'
         25        INIT_FCALL                                               'period_to_timestamps'
         26        SEND_VAL                                                 'last_year'
         27        DO_FCALL                                      0  $8      
         28        SEND_VAR                                                 $8
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Function period_to_timestamps:
Finding entry points
Branch analysis from position: 0
7 jumps found. (Code = 188) Position 1 = 13, Position 2 = 22, Position 3 = 31, Position 4 = 40, Position 5 = 57, Position 6 = 82, Position 7 = 2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 31
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 40
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 57
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
Branch analysis from position: 57
Branch analysis from position: 40
Branch analysis from position: 31
Branch analysis from position: 22
Branch analysis from position: 13
filename:       /in/DfLJ0
function name:  period_to_timestamps
number of ops:  102
compiled vars:  !0 = $period, !1 = $start, !2 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1      > SWITCH_STRING                                            !0, [ 'last_7_days':->13, 'this_month':->22, 'last_month':->31, 'this_year':->40, 'last_year':->57, ], ->82
    5     2    >   IS_EQUAL                                                 !0, 'last_7_days'
          3      > JMPNZ                                                    ~3, ->13
    9     4    >   IS_EQUAL                                                 !0, 'this_month'
          5      > JMPNZ                                                    ~3, ->22
   13     6    >   IS_EQUAL                                                 !0, 'last_month'
          7      > JMPNZ                                                    ~3, ->31
   17     8    >   IS_EQUAL                                                 !0, 'this_year'
          9      > JMPNZ                                                    ~3, ->40
   21    10    >   IS_EQUAL                                                 !0, 'last_year'
         11      > JMPNZ                                                    ~3, ->57
         12    > > JMP                                                      ->82
    6    13    >   INIT_FCALL                                               'strtotime'
         14        SEND_VAL                                                 '-7+days'
         15        DO_ICALL                                         $4      
         16        ASSIGN                                                   !1, $4
    7    17        INIT_FCALL                                               'strtotime'
         18        SEND_VAL                                                 'now'
         19        DO_ICALL                                         $6      
         20        ASSIGN                                                   !2, $6
    8    21      > JMP                                                      ->90
   10    22    >   INIT_FCALL                                               'strtotime'
         23        SEND_VAL                                                 'first+day+of+this+month'
         24        DO_ICALL                                         $8      
         25        ASSIGN                                                   !1, $8
   11    26        INIT_FCALL                                               'strtotime'
         27        SEND_VAL                                                 'now'
         28        DO_ICALL                                         $10     
         29        ASSIGN                                                   !2, $10
   12    30      > JMP                                                      ->90
   14    31    >   INIT_FCALL                                               'strtotime'
         32        SEND_VAL                                                 'first+day+of+last+month'
         33        DO_ICALL                                         $12     
         34        ASSIGN                                                   !1, $12
   15    35        INIT_FCALL                                               'strtotime'
         36        SEND_VAL                                                 'last+day+of+last+month'
         37        DO_ICALL                                         $14     
         38        ASSIGN                                                   !2, $14
   16    39      > JMP                                                      ->90
   18    40    >   INIT_FCALL                                               'strtotime'
         41        INIT_FCALL                                               'date'
         42        SEND_VAL                                                 'Y'
         43        INIT_FCALL                                               'strtotime'
         44        SEND_VAL                                                 'now'
         45        DO_ICALL                                         $16     
         46        SEND_VAR                                                 $16
         47        DO_ICALL                                         $17     
         48        CONCAT                                           ~18     '01-01-', $17
         49        SEND_VAL                                                 ~18
         50        DO_ICALL                                         $19     
         51        ASSIGN                                                   !1, $19
   19    52        INIT_FCALL                                               'strtotime'
         53        SEND_VAL                                                 'now'
         54        DO_ICALL                                         $21     
         55        ASSIGN                                                   !2, $21
   20    56      > JMP                                                      ->90
   22    57    >   INIT_FCALL                                               'strtotime'
         58        INIT_FCALL                                               'date'
         59        SEND_VAL                                                 'Y'
         60        INIT_FCALL                                               'strtotime'
         61        SEND_VAL                                                 'now+-1+year'
         62        DO_ICALL                                         $23     
         63        SEND_VAR                                                 $23
         64        DO_ICALL                                         $24     
         65        CONCAT                                           ~25     '01%2F01%2F', $24
         66        SEND_VAL                                                 ~25
         67        DO_ICALL                                         $26     
         68        ASSIGN                                                   !1, $26
   23    69        INIT_FCALL                                               'strtotime'
         70        INIT_FCALL                                               'date'
         71        SEND_VAL                                                 'Y'
         72        INIT_FCALL                                               'strtotime'
         73        SEND_VAL                                                 'now+-1+year'
         74        DO_ICALL                                         $28     
         75        SEND_VAR                                                 $28
         76        DO_ICALL                                         $29     
         77        CONCAT                                           ~30     '12%2F31%2F', $29
         78        SEND_VAL                                                 ~30
         79        DO_ICALL                                         $31     
         80        ASSIGN                                                   !2, $31
   24    81      > JMP                                                      ->90
   26    82    >   INIT_FCALL                                               'strtotime'
         83        SEND_VAL                                                 'now'
         84        DO_ICALL                                         $33     
         85        ASSIGN                                                   !1, $33
   27    86        INIT_FCALL                                               'strtotime'
         87        SEND_VAL                                                 'now'
         88        DO_ICALL                                         $35     
         89        ASSIGN                                                   !2, $35
   30    90    >   INIT_FCALL                                               'date'
         91        SEND_VAL                                                 'm-d-Y'
         92        SEND_VAR                                                 !1
         93        DO_ICALL                                         $37     
         94        INIT_ARRAY                                       ~38     $37
         95        INIT_FCALL                                               'date'
         96        SEND_VAL                                                 'm-d-Y'
         97        SEND_VAR                                                 !2
         98        DO_ICALL                                         $39     
         99        ADD_ARRAY_ELEMENT                                ~38     $39
        100      > RETURN                                                   ~38
   31   101*     > RETURN                                                   null

End of function period_to_timestamps

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.53 ms | 1410 KiB | 24 Q