3v4l.org

run code in 300+ PHP versions simultaneously
<?php function calcDays($startdate, $enddate) { $first = $startdate < $enddate ? $startdate : $enddate; $second = $startdate < $enddate ? $enddate : $startdate; $inbetween = $second - $first; $i[0] = 60; $i[1] = 24; $i[2] = 7; $i[3] = date('t', strtotime('-1 month', $second)); $i[4] = date('L', strtotime('-1 year', $second)) ? 366 : 365; $i[5] = array(31, (date('L', strtotime('-1 year', $second)) ? 28 : 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $months = 0; $days = 0; $temp = floor($inbetween / $i[0] / $i[0] / $i[1]); $tempDays = floor($temp % 365); $tempMonth = date('n', strtotime('-1 year', $second)) - 1; for($n = 0; $n < 12; $n++) { if($tempDays >= $i[5][$tempMonth]) { $months += 1; $tempDays -= $i[5][$tempMonth]; } else { $days = $tempDays; break; } $tempMonth = $tempMonth < 10 ? $tempMonth + 1 : 0; } $years = floor(date('Y', $second) - date('Y', $first) + $months / 12); $months = $months % 12; $hours = floor($inbetween / $i[0] / $i[0] % $i[1]); $minutes = floor($inbetween / $i[0] % $i[0]); $seconds = $inbetween % $i[0]; $dateObj = new stdClass(); $dateObj->years = $years; $dateObj->months = $months; $dateObj->days = $days; $dateObj->hours = $hours; $dateObj->minutes = $minutes; $dateObj->seconds = $seconds; return $dateObj; } $mydate = calcDays(1388534400, 1454198400); echo $mydate->years;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QBVT7
function name:  (null)
number of ops:  8
compiled vars:  !0 = $mydate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   INIT_FCALL                                               'calcdays'
          1        SEND_VAL                                                 1388534400
          2        SEND_VAL                                                 1454198400
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   56     5        FETCH_OBJ_R                                      ~3      !0, 'years'
          6        ECHO                                                     ~3
          7      > RETURN                                                   1

Function calcdays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 120
Branch analysis from position: 120
2 jumps found. (Code = 44) Position 1 = 122, Position 2 = 101
Branch analysis from position: 122
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 101
2 jumps found. (Code = 43) Position 1 = 105, Position 2 = 110
Branch analysis from position: 105
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 114, Position 2 = 117
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 118
Branch analysis from position: 118
2 jumps found. (Code = 44) Position 1 = 122, Position 2 = 101
Branch analysis from position: 122
Branch analysis from position: 101
Branch analysis from position: 117
2 jumps found. (Code = 44) Position 1 = 122, Position 2 = 101
Branch analysis from position: 122
Branch analysis from position: 101
Branch analysis from position: 110
1 jumps found. (Code = 42) Position 1 = 122
Branch analysis from position: 122
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 120
Branch analysis from position: 120
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 58
Branch analysis from position: 56
Branch analysis from position: 58
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
Branch analysis from position: 43
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
Branch analysis from position: 12
filename:       /in/QBVT7
function name:  calcDays
number of ops:  177
compiled vars:  !0 = $startdate, !1 = $enddate, !2 = $first, !3 = $second, !4 = $inbetween, !5 = $i, !6 = $months, !7 = $days, !8 = $temp, !9 = $tempDays, !10 = $tempMonth, !11 = $n, !12 = $years, !13 = $hours, !14 = $minutes, !15 = $seconds, !16 = $dateObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        IS_SMALLER                                               !0, !1
          3      > JMPZ                                                     ~17, ->6
          4    >   QM_ASSIGN                                        ~18     !0
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~18     !1
          7    >   ASSIGN                                                   !2, ~18
    5     8        IS_SMALLER                                               !0, !1
          9      > JMPZ                                                     ~20, ->12
         10    >   QM_ASSIGN                                        ~21     !1
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~21     !0
         13    >   ASSIGN                                                   !3, ~21
    6    14        SUB                                              ~23     !3, !2
         15        ASSIGN                                                   !4, ~23
    8    16        ASSIGN_DIM                                               !5, 0
         17        OP_DATA                                                  60
    9    18        ASSIGN_DIM                                               !5, 1
         19        OP_DATA                                                  24
   10    20        ASSIGN_DIM                                               !5, 2
         21        OP_DATA                                                  7
   11    22        INIT_FCALL                                               'date'
         23        SEND_VAL                                                 't'
         24        INIT_FCALL                                               'strtotime'
         25        SEND_VAL                                                 '-1+month'
         26        SEND_VAR                                                 !3
         27        DO_ICALL                                         $29     
         28        SEND_VAR                                                 $29
         29        DO_ICALL                                         $30     
         30        ASSIGN_DIM                                               !5, 3
         31        OP_DATA                                                  $30
   12    32        INIT_FCALL                                               'date'
         33        SEND_VAL                                                 'L'
         34        INIT_FCALL                                               'strtotime'
         35        SEND_VAL                                                 '-1+year'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                         $32     
         38        SEND_VAR                                                 $32
         39        DO_ICALL                                         $33     
         40      > JMPZ                                                     $33, ->43
         41    >   QM_ASSIGN                                        ~34     366
         42      > JMP                                                      ->44
         43    >   QM_ASSIGN                                        ~34     365
         44    >   ASSIGN_DIM                                               !5, 4
         45        OP_DATA                                                  ~34
   13    46        INIT_ARRAY                                       ~36     31
         47        INIT_FCALL                                               'date'
         48        SEND_VAL                                                 'L'
         49        INIT_FCALL                                               'strtotime'
         50        SEND_VAL                                                 '-1+year'
         51        SEND_VAR                                                 !3
         52        DO_ICALL                                         $37     
         53        SEND_VAR                                                 $37
         54        DO_ICALL                                         $38     
         55      > JMPZ                                                     $38, ->58
         56    >   QM_ASSIGN                                        ~39     28
         57      > JMP                                                      ->59
         58    >   QM_ASSIGN                                        ~39     29
         59    >   ADD_ARRAY_ELEMENT                                ~36     ~39
         60        ADD_ARRAY_ELEMENT                                ~36     31
         61        ADD_ARRAY_ELEMENT                                ~36     30
         62        ADD_ARRAY_ELEMENT                                ~36     31
         63        ADD_ARRAY_ELEMENT                                ~36     30
         64        ADD_ARRAY_ELEMENT                                ~36     31
         65        ADD_ARRAY_ELEMENT                                ~36     31
         66        ADD_ARRAY_ELEMENT                                ~36     30
         67        ADD_ARRAY_ELEMENT                                ~36     31
         68        ADD_ARRAY_ELEMENT                                ~36     30
         69        ADD_ARRAY_ELEMENT                                ~36     31
         70        ASSIGN_DIM                                               !5, 5
         71        OP_DATA                                                  ~36
   15    72        ASSIGN                                                   !6, 0
   16    73        ASSIGN                                                   !7, 0
   18    74        INIT_FCALL                                               'floor'
         75        FETCH_DIM_R                                      ~42     !5, 0
         76        DIV                                              ~43     !4, ~42
         77        FETCH_DIM_R                                      ~44     !5, 0
         78        DIV                                              ~45     ~43, ~44
         79        FETCH_DIM_R                                      ~46     !5, 1
         80        DIV                                              ~47     ~45, ~46
         81        SEND_VAL                                                 ~47
         82        DO_ICALL                                         $48     
         83        ASSIGN                                                   !8, $48
   19    84        INIT_FCALL                                               'floor'
         85        MOD                                              ~50     !8, 365
         86        SEND_VAL                                                 ~50
         87        DO_ICALL                                         $51     
         88        ASSIGN                                                   !9, $51
   20    89        INIT_FCALL                                               'date'
         90        SEND_VAL                                                 'n'
         91        INIT_FCALL                                               'strtotime'
         92        SEND_VAL                                                 '-1+year'
         93        SEND_VAR                                                 !3
         94        DO_ICALL                                         $53     
         95        SEND_VAR                                                 $53
         96        DO_ICALL                                         $54     
         97        SUB                                              ~55     $54, 1
         98        ASSIGN                                                   !10, ~55
   22    99        ASSIGN                                                   !11, 0
        100      > JMP                                                      ->120
   23   101    >   FETCH_DIM_R                                      ~58     !5, 5
        102        FETCH_DIM_R                                      ~59     ~58, !10
        103        IS_SMALLER_OR_EQUAL                                      ~59, !9
        104      > JMPZ                                                     ~60, ->110
   24   105    >   ASSIGN_OP                                     1          !6, 1
   25   106        FETCH_DIM_R                                      ~62     !5, 5
        107        FETCH_DIM_R                                      ~63     ~62, !10
        108        ASSIGN_OP                                     2          !9, ~63
        109      > JMP                                                      ->112
   27   110    >   ASSIGN                                                   !7, !9
   28   111      > JMP                                                      ->122
   31   112    >   IS_SMALLER                                               !10, 10
        113      > JMPZ                                                     ~66, ->117
        114    >   ADD                                              ~67     !10, 1
        115        QM_ASSIGN                                        ~68     ~67
        116      > JMP                                                      ->118
        117    >   QM_ASSIGN                                        ~68     0
        118    >   ASSIGN                                                   !10, ~68
   22   119        PRE_INC                                                  !11
        120    >   IS_SMALLER                                               !11, 12
        121      > JMPNZ                                                    ~71, ->101
   35   122    >   INIT_FCALL                                               'floor'
        123        INIT_FCALL                                               'date'
        124        SEND_VAL                                                 'Y'
        125        SEND_VAR                                                 !3
        126        DO_ICALL                                         $72     
        127        INIT_FCALL                                               'date'
        128        SEND_VAL                                                 'Y'
        129        SEND_VAR                                                 !2
        130        DO_ICALL                                         $73     
        131        SUB                                              ~74     $72, $73
        132        DIV                                              ~75     !6, 12
        133        ADD                                              ~76     ~74, ~75
        134        SEND_VAL                                                 ~76
        135        DO_ICALL                                         $77     
        136        ASSIGN                                                   !12, $77
   36   137        MOD                                              ~79     !6, 12
        138        ASSIGN                                                   !6, ~79
   38   139        INIT_FCALL                                               'floor'
        140        FETCH_DIM_R                                      ~81     !5, 0
        141        DIV                                              ~82     !4, ~81
        142        FETCH_DIM_R                                      ~83     !5, 0
        143        DIV                                              ~84     ~82, ~83
        144        FETCH_DIM_R                                      ~85     !5, 1
        145        MOD                                              ~86     ~84, ~85
        146        SEND_VAL                                                 ~86
        147        DO_ICALL                                         $87     
        148        ASSIGN                                                   !13, $87
   39   149        INIT_FCALL                                               'floor'
        150        FETCH_DIM_R                                      ~89     !5, 0
        151        DIV                                              ~90     !4, ~89
        152        FETCH_DIM_R                                      ~91     !5, 0
        153        MOD                                              ~92     ~90, ~91
        154        SEND_VAL                                                 ~92
        155        DO_ICALL                                         $93     
        156        ASSIGN                                                   !14, $93
   40   157        FETCH_DIM_R                                      ~95     !5, 0
        158        MOD                                              ~96     !4, ~95
        159        ASSIGN                                                   !15, ~96
   42   160        NEW                                              $98     'stdClass'
        161        DO_FCALL                                      0          
        162        ASSIGN                                                   !16, $98
   44   163        ASSIGN_OBJ                                               !16, 'years'
        164        OP_DATA                                                  !12
   45   165        ASSIGN_OBJ                                               !16, 'months'
        166        OP_DATA                                                  !6
   46   167        ASSIGN_OBJ                                               !16, 'days'
        168        OP_DATA                                                  !7
   47   169        ASSIGN_OBJ                                               !16, 'hours'
        170        OP_DATA                                                  !13
   48   171        ASSIGN_OBJ                                               !16, 'minutes'
        172        OP_DATA                                                  !14
   49   173        ASSIGN_OBJ                                               !16, 'seconds'
        174        OP_DATA                                                  !15
   51   175      > RETURN                                                   !16
   52   176*     > RETURN                                                   null

End of function calcdays

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.87 ms | 1415 KiB | 20 Q