3v4l.org

run code in 300+ PHP versions simultaneously
<?php print_r(get_thirty_days(new \DateTime())); print_r(get_thirty_days(new \DateTime('2017-01-15'), 40)); print_r(array_reverse(get_thirty_days(new \DateTime('2017-01-15'), 10))); function get_thirty_days(\DateTime $date_in, int $days = null) { $days = $days ?? 30; $date_out = $date_in->add(new \DateInterval(sprintf('P%dD', $days))); $dates = []; while ($days) { $dates[] = $date_out ->sub(new \DateInterval('P1D')) ->format('Ymd') ; $days--; } return $dates; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5QjEr
function name:  (null)
number of ops:  32
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL_BY_NAME                                       'get_thirty_days'
          2        NEW                                              $0      'DateTime'
          3        DO_FCALL                                      0          
          4        SEND_VAR_NO_REF_EX                                       $0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
    4     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL_BY_NAME                                       'get_thirty_days'
         10        NEW                                              $4      'DateTime'
         11        SEND_VAL_EX                                              '2017-01-15'
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $4
         14        SEND_VAL_EX                                              40
         15        DO_FCALL                                      0  $6      
         16        SEND_VAR                                                 $6
         17        DO_ICALL                                                 
    5    18        INIT_FCALL                                               'print_r'
         19        INIT_FCALL                                               'array_reverse'
         20        INIT_FCALL_BY_NAME                                       'get_thirty_days'
         21        NEW                                              $8      'DateTime'
         22        SEND_VAL_EX                                              '2017-01-15'
         23        DO_FCALL                                      0          
         24        SEND_VAR_NO_REF_EX                                       $8
         25        SEND_VAL_EX                                              10
         26        DO_FCALL                                      0  $10     
         27        SEND_VAR                                                 $10
         28        DO_ICALL                                         $11     
         29        SEND_VAR                                                 $11
         30        DO_ICALL                                                 
   22    31      > RETURN                                                   1

Function get_thirty_days:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 18
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 18
Branch analysis from position: 31
Branch analysis from position: 18
filename:       /in/5QjEr
function name:  get_thirty_days
number of ops:  33
compiled vars:  !0 = $date_in, !1 = $days, !2 = $date_out, !3 = $dates
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    8     2        COALESCE                                         ~4      !1
          3        QM_ASSIGN                                        ~4      30
          4        ASSIGN                                                   !1, ~4
    9     5        INIT_METHOD_CALL                                         !0, 'add'
          6        NEW                                              $6      'DateInterval'
          7        INIT_FCALL                                               'sprintf'
          8        SEND_VAL                                                 'P%25dD'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $7      
         11        SEND_VAR_NO_REF_EX                                       $7
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $6
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !2, $9
   10    16        ASSIGN                                                   !3, <array>
   12    17      > JMP                                                      ->30
   14    18    >   INIT_METHOD_CALL                                         !2, 'sub'
         19        NEW                                              $13     'DateInterval'
         20        SEND_VAL_EX                                              'P1D'
         21        DO_FCALL                                      0          
         22        SEND_VAR_NO_REF_EX                                       $13
         23        DO_FCALL                                      0  $15     
   15    24        INIT_METHOD_CALL                                         $15, 'format'
         25        SEND_VAL_EX                                              'Ymd'
         26        DO_FCALL                                      0  $16     
   13    27        ASSIGN_DIM                                               !3
   15    28        OP_DATA                                                  $16
   18    29        PRE_DEC                                                  !1
   12    30    > > JMPNZ                                                    !1, ->18
   21    31    > > RETURN                                                   !3
   22    32*     > RETURN                                                   null

End of function get_thirty_days

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.16 ms | 1007 KiB | 16 Q