3v4l.org

run code in 300+ PHP versions simultaneously
<?php function add_weeks($weeks = 1, $base = 'now') { // normalise base to a unix timestamp if (!is_string($base)) { $base = intval($base); } else { $base = strtotime($base); } // get the date one week from the base $result = strtotime(sprintf("@{$base} +{$weeks} weeks", $base, $weeks)); // if it falls in a different month, get the last day of the base month if (date('n', $base) !== date('n', $result)) { $result = strtotime("@{$base} last day of month"); } return $result; } echo date('Y-m-d', add_weeks(1)) . "\n"; echo date('Y-m-d', add_weeks(2)) . "\n"; echo date('Y-m-d', add_weeks(1, '2012-06-18')) . "\n"; echo date('Y-m-d', add_weeks(2, '2012-06-18')) . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ksgre
function name:  (null)
number of ops:  39
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'date'
          1        SEND_VAL                                                 'Y-m-d'
          2        INIT_FCALL                                               'add_weeks'
          3        SEND_VAL                                                 1
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                         $1      
          7        CONCAT                                           ~2      $1, '%0A'
          8        ECHO                                                     ~2
   24     9        INIT_FCALL                                               'date'
         10        SEND_VAL                                                 'Y-m-d'
         11        INIT_FCALL                                               'add_weeks'
         12        SEND_VAL                                                 2
         13        DO_FCALL                                      0  $3      
         14        SEND_VAR                                                 $3
         15        DO_ICALL                                         $4      
         16        CONCAT                                           ~5      $4, '%0A'
         17        ECHO                                                     ~5
   25    18        INIT_FCALL                                               'date'
         19        SEND_VAL                                                 'Y-m-d'
         20        INIT_FCALL                                               'add_weeks'
         21        SEND_VAL                                                 1
         22        SEND_VAL                                                 '2012-06-18'
         23        DO_FCALL                                      0  $6      
         24        SEND_VAR                                                 $6
         25        DO_ICALL                                         $7      
         26        CONCAT                                           ~8      $7, '%0A'
         27        ECHO                                                     ~8
   26    28        INIT_FCALL                                               'date'
         29        SEND_VAL                                                 'Y-m-d'
         30        INIT_FCALL                                               'add_weeks'
         31        SEND_VAL                                                 2
         32        SEND_VAL                                                 '2012-06-18'
         33        DO_FCALL                                      0  $9      
         34        SEND_VAR                                                 $9
         35        DO_ICALL                                         $10     
         36        CONCAT                                           ~11     $10, '%0A'
         37        ECHO                                                     ~11
         38      > RETURN                                                   1

Function add_weeks:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
Branch analysis from position: 43
filename:       /in/ksgre
function name:  add_weeks
number of ops:  45
compiled vars:  !0 = $weeks, !1 = $base, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                        !0      1
          1        RECV_INIT                                        !1      'now'
    6     2        TYPE_CHECK                                   64  ~3      !1
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->8
    7     5    >   CAST                                          4  ~5      !1
          6        ASSIGN                                                   !1, ~5
          7      > JMP                                                      ->12
    9     8    >   INIT_FCALL                                               'strtotime'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !1, $7
   13    12    >   INIT_FCALL                                               'strtotime'
         13        INIT_FCALL                                               'sprintf'
         14        ROPE_INIT                                     5  ~10     '%40'
         15        ROPE_ADD                                      1  ~10     ~10, !1
         16        ROPE_ADD                                      2  ~10     ~10, '+%2B'
         17        ROPE_ADD                                      3  ~10     ~10, !0
         18        ROPE_END                                      4  ~9      ~10, '+weeks'
         19        SEND_VAL                                                 ~9
         20        SEND_VAR                                                 !1
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $13     
         23        SEND_VAR                                                 $13
         24        DO_ICALL                                         $14     
         25        ASSIGN                                                   !2, $14
   16    26        INIT_FCALL                                               'date'
         27        SEND_VAL                                                 'n'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $16     
         30        INIT_FCALL                                               'date'
         31        SEND_VAL                                                 'n'
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                         $17     
         34        IS_NOT_IDENTICAL                                         $16, $17
         35      > JMPZ                                                     ~18, ->43
   17    36    >   INIT_FCALL                                               'strtotime'
         37        ROPE_INIT                                     3  ~20     '%40'
         38        ROPE_ADD                                      1  ~20     ~20, !1
         39        ROPE_END                                      2  ~19     ~20, '+last+day+of+month'
         40        SEND_VAL                                                 ~19
         41        DO_ICALL                                         $22     
         42        ASSIGN                                                   !2, $22
   20    43    > > RETURN                                                   !2
   21    44*     > RETURN                                                   null

End of function add_weeks

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
209.3 ms | 1402 KiB | 23 Q