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

End of function datediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
193.51 ms | 1411 KiB | 20 Q