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

End of function datediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.29 ms | 1406 KiB | 22 Q