3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dateDiff($startdate, $enddate) { $first = $startdate < $enddate ? $startdate : $enddate; $second = $startdate < $enddate ? $enddate : $startdate; $inbetween = $second - $first; $i[0] = 60; $i[1] = 24; $i[2] = array(31, (date('L', strtotime('-1 year', $second)) ? 28 : 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $months = 0; $days = 0; $tempDays = $inbetween / $i[0] / $i[0] / $i[1] % 365.25; var_dump($tempDays); $tempMonth = date('n', strtotime('-1 year', $second)) - 1; for($n = 0; $n < 12; $n++) { if($tempDays >= $i[2][$tempMonth]) { $months += 1; $tempDays -= $i[2][$tempMonth]; } else { $days = round($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 = dateDiff(1388534400, 12417395661); echo $mydate->years, " years, ", $mydate->months, " months, ", $mydate->days, " days, ", $mydate->hours, " hours, ", $mydate->minutes, " minutes, and ", $mydate->seconds, " seconds";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dD357
function name:  (null)
number of ops:  24
compiled vars:  !0 = $mydate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   INIT_FCALL                                               'datediff'
          1        SEND_VAL                                                 1388534400
          2        SEND_VAL                                                 12417395661
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   52     5        FETCH_OBJ_R                                      ~3      !0, 'years'
          6        ECHO                                                     ~3
          7        ECHO                                                     '+years%2C+'
          8        FETCH_OBJ_R                                      ~4      !0, 'months'
          9        ECHO                                                     ~4
         10        ECHO                                                     '+months%2C+'
         11        FETCH_OBJ_R                                      ~5      !0, 'days'
         12        ECHO                                                     ~5
         13        ECHO                                                     '+days%2C+'
         14        FETCH_OBJ_R                                      ~6      !0, 'hours'
         15        ECHO                                                     ~6
         16        ECHO                                                     '+hours%2C+'
         17        FETCH_OBJ_R                                      ~7      !0, 'minutes'
         18        ECHO                                                     ~7
         19        ECHO                                                     '+minutes%2C+and+'
         20        FETCH_OBJ_R                                      ~8      !0, 'seconds'
         21        ECHO                                                     ~8
         22        ECHO                                                     '+seconds'
         23      > RETURN                                                   1

Function datediff:
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 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 71
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 80
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 90
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 71
Branch analysis from position: 95
Branch analysis from position: 71
Branch analysis from position: 90
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 71
Branch analysis from position: 95
Branch analysis from position: 71
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 95
Branch analysis from position: 95
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
Branch analysis from position: 32
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/dD357
function name:  dateDiff
number of ops:  150
compiled vars:  !0 = $startdate, !1 = $enddate, !2 = $first, !3 = $second, !4 = $inbetween, !5 = $i, !6 = $months, !7 = $days, !8 = $tempDays, !9 = $tempMonth, !10 = $n, !11 = $years, !12 = $hours, !13 = $minutes, !14 = $seconds, !15 = $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                                                     ~16, ->6
          4    >   QM_ASSIGN                                        ~17     !0
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~17     !1
          7    >   ASSIGN                                                   !2, ~17
    5     8        IS_SMALLER                                               !0, !1
          9      > JMPZ                                                     ~19, ->12
         10    >   QM_ASSIGN                                        ~20     !1
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~20     !0
         13    >   ASSIGN                                                   !3, ~20
    6    14        SUB                                              ~22     !3, !2
         15        ASSIGN                                                   !4, ~22
    8    16        ASSIGN_DIM                                               !5, 0
         17        OP_DATA                                                  60
    9    18        ASSIGN_DIM                                               !5, 1
         19        OP_DATA                                                  24
   10    20        INIT_ARRAY                                       ~27     31
         21        INIT_FCALL                                               'date'
         22        SEND_VAL                                                 'L'
         23        INIT_FCALL                                               'strtotime'
         24        SEND_VAL                                                 '-1+year'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                         $28     
         27        SEND_VAR                                                 $28
         28        DO_ICALL                                         $29     
         29      > JMPZ                                                     $29, ->32
         30    >   QM_ASSIGN                                        ~30     28
         31      > JMP                                                      ->33
         32    >   QM_ASSIGN                                        ~30     29
         33    >   ADD_ARRAY_ELEMENT                                ~27     ~30
         34        ADD_ARRAY_ELEMENT                                ~27     31
         35        ADD_ARRAY_ELEMENT                                ~27     30
         36        ADD_ARRAY_ELEMENT                                ~27     31
         37        ADD_ARRAY_ELEMENT                                ~27     30
         38        ADD_ARRAY_ELEMENT                                ~27     31
         39        ADD_ARRAY_ELEMENT                                ~27     31
         40        ADD_ARRAY_ELEMENT                                ~27     30
         41        ADD_ARRAY_ELEMENT                                ~27     31
         42        ADD_ARRAY_ELEMENT                                ~27     30
         43        ADD_ARRAY_ELEMENT                                ~27     31
         44        ASSIGN_DIM                                               !5, 2
         45        OP_DATA                                                  ~27
   12    46        ASSIGN                                                   !6, 0
   13    47        ASSIGN                                                   !7, 0
   15    48        FETCH_DIM_R                                      ~33     !5, 0
         49        DIV                                              ~34     !4, ~33
         50        FETCH_DIM_R                                      ~35     !5, 0
         51        DIV                                              ~36     ~34, ~35
         52        FETCH_DIM_R                                      ~37     !5, 1
         53        DIV                                              ~38     ~36, ~37
         54        MOD                                              ~39     ~38, 365.25
         55        ASSIGN                                                   !8, ~39
   16    56        INIT_FCALL                                               'var_dump'
         57        SEND_VAR                                                 !8
         58        DO_ICALL                                                 
   17    59        INIT_FCALL                                               'date'
         60        SEND_VAL                                                 'n'
         61        INIT_FCALL                                               'strtotime'
         62        SEND_VAL                                                 '-1+year'
         63        SEND_VAR                                                 !3
         64        DO_ICALL                                         $42     
         65        SEND_VAR                                                 $42
         66        DO_ICALL                                         $43     
         67        SUB                                              ~44     $43, 1
         68        ASSIGN                                                   !9, ~44
   19    69        ASSIGN                                                   !10, 0
         70      > JMP                                                      ->93
   20    71    >   FETCH_DIM_R                                      ~47     !5, 2
         72        FETCH_DIM_R                                      ~48     ~47, !9
         73        IS_SMALLER_OR_EQUAL                                      ~48, !8
         74      > JMPZ                                                     ~49, ->80
   21    75    >   ASSIGN_OP                                     1          !6, 1
   22    76        FETCH_DIM_R                                      ~51     !5, 2
         77        FETCH_DIM_R                                      ~52     ~51, !9
         78        ASSIGN_OP                                     2          !8, ~52
         79      > JMP                                                      ->85
   24    80    >   INIT_FCALL                                               'round'
         81        SEND_VAR                                                 !8
         82        DO_ICALL                                         $54     
         83        ASSIGN                                                   !7, $54
   25    84      > JMP                                                      ->95
   28    85    >   IS_SMALLER                                               !9, 10
         86      > JMPZ                                                     ~56, ->90
         87    >   ADD                                              ~57     !9, 1
         88        QM_ASSIGN                                        ~58     ~57
         89      > JMP                                                      ->91
         90    >   QM_ASSIGN                                        ~58     0
         91    >   ASSIGN                                                   !9, ~58
   19    92        PRE_INC                                                  !10
         93    >   IS_SMALLER                                               !10, 12
         94      > JMPNZ                                                    ~61, ->71
   31    95    >   INIT_FCALL                                               'floor'
         96        INIT_FCALL                                               'date'
         97        SEND_VAL                                                 'Y'
         98        SEND_VAR                                                 !3
         99        DO_ICALL                                         $62     
        100        INIT_FCALL                                               'date'
        101        SEND_VAL                                                 'Y'
        102        SEND_VAR                                                 !2
        103        DO_ICALL                                         $63     
        104        SUB                                              ~64     $62, $63
        105        DIV                                              ~65     !6, 12
        106        ADD                                              ~66     ~64, ~65
        107        SEND_VAL                                                 ~66
        108        DO_ICALL                                         $67     
        109        ASSIGN                                                   !11, $67
   32   110        MOD                                              ~69     !6, 12
        111        ASSIGN                                                   !6, ~69
   34   112        INIT_FCALL                                               'floor'
        113        FETCH_DIM_R                                      ~71     !5, 0
        114        DIV                                              ~72     !4, ~71
        115        FETCH_DIM_R                                      ~73     !5, 0
        116        DIV                                              ~74     ~72, ~73
        117        FETCH_DIM_R                                      ~75     !5, 1
        118        MOD                                              ~76     ~74, ~75
        119        SEND_VAL                                                 ~76
        120        DO_ICALL                                         $77     
        121        ASSIGN                                                   !12, $77
   35   122        INIT_FCALL                                               'floor'
        123        FETCH_DIM_R                                      ~79     !5, 0
        124        DIV                                              ~80     !4, ~79
        125        FETCH_DIM_R                                      ~81     !5, 0
        126        MOD                                              ~82     ~80, ~81
        127        SEND_VAL                                                 ~82
        128        DO_ICALL                                         $83     
        129        ASSIGN                                                   !13, $83
   36   130        FETCH_DIM_R                                      ~85     !5, 0
        131        MOD                                              ~86     !4, ~85
        132        ASSIGN                                                   !14, ~86
   38   133        NEW                                              $88     'stdClass'
        134        DO_FCALL                                      0          
        135        ASSIGN                                                   !15, $88
   40   136        ASSIGN_OBJ                                               !15, 'years'
        137        OP_DATA                                                  !11
   41   138        ASSIGN_OBJ                                               !15, 'months'
        139        OP_DATA                                                  !6
   42   140        ASSIGN_OBJ                                               !15, 'days'
        141        OP_DATA                                                  !7
   43   142        ASSIGN_OBJ                                               !15, 'hours'
        143        OP_DATA                                                  !12
   44   144        ASSIGN_OBJ                                               !15, 'minutes'
        145        OP_DATA                                                  !13
   45   146        ASSIGN_OBJ                                               !15, 'seconds'
        147        OP_DATA                                                  !14
   47   148      > RETURN                                                   !15
   48   149*     > RETURN                                                   null

End of function datediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.96 ms | 1406 KiB | 24 Q