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; $firsttemp = $first; $months = 0; $days = 0; while(TRUE) { if($firsttemp + 86400 * date('t', $firsttemp) <= $second) { $months += 1; $firsttemp += 86400 * date('t', $firsttemp); } else { if($second - $firsttemp >= 86400) { $days = floor(($second - $firsttemp) / 86400); } break; } } $years = floor($months / 12); $months = $months % 12; $hours = floor($inbetween / 60 / 60 % 24); $minutes = floor($inbetween / 60 % 60); $seconds = $inbetween % 60; $dateObj = new stdClass(); $dateObj->y = $years; $dateObj->m = $months; $dateObj->d = $days; $dateObj->h = $hours; $dateObj->i = $minutes; $dateObj->s = $seconds; $dateObj->days = floor($inbetween / 86400); return $dateObj; } $str1 = "1970-01-01"; $str2 = "2009-01-01"; $interval = dateDiff(strtotime($str1), strtotime($str2)); echo "difference " . $interval->y . " years, " . $interval->m . " months, " . $interval->d . " days";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7ePZN
function name:  (null)
number of ops:  24
compiled vars:  !0 = $str1, !1 = $str2, !2 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ASSIGN                                                   !0, '1970-01-01'
   46     1        ASSIGN                                                   !1, '2009-01-01'
   48     2        INIT_FCALL                                               'datediff'
          3        INIT_FCALL                                               'strtotime'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        SEND_VAR                                                 $5
          7        INIT_FCALL                                               'strtotime'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !2, $7
   50    13        FETCH_OBJ_R                                      ~9      !2, 'y'
         14        CONCAT                                           ~10     'difference+', ~9
         15        CONCAT                                           ~11     ~10, '+years%2C+'
         16        FETCH_OBJ_R                                      ~12     !2, 'm'
         17        CONCAT                                           ~13     ~11, ~12
         18        CONCAT                                           ~14     ~13, '+months%2C+'
         19        FETCH_OBJ_R                                      ~15     !2, 'd'
         20        CONCAT                                           ~16     ~14, ~15
         21        CONCAT                                           ~17     ~16, '+days'
         22        ECHO                                                     ~17
         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
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 20
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 36
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 45
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 45
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
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/7ePZN
function name:  dateDiff
number of ops:  92
compiled vars:  !0 = $startdate, !1 = $enddate, !2 = $first, !3 = $second, !4 = $inbetween, !5 = $firsttemp, !6 = $months, !7 = $days, !8 = $years, !9 = $hours, !10 = $minutes, !11 = $seconds, !12 = $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                                                     ~13, ->6
          4    >   QM_ASSIGN                                        ~14     !0
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~14     !1
          7    >   ASSIGN                                                   !2, ~14
    5     8        IS_SMALLER                                               !0, !1
          9      > JMPZ                                                     ~16, ->12
         10    >   QM_ASSIGN                                        ~17     !1
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~17     !0
         13    >   ASSIGN                                                   !3, ~17
    6    14        SUB                                              ~19     !3, !2
         15        ASSIGN                                                   !4, ~19
    7    16        ASSIGN                                                   !5, !2
    9    17        ASSIGN                                                   !6, 0
   10    18        ASSIGN                                                   !7, 0
   12    19      > JMP                                                      ->46
   13    20    >   INIT_FCALL                                               'date'
         21        SEND_VAL                                                 't'
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $24     
         24        MUL                                              ~25     $24, 86400
         25        ADD                                              ~26     !5, ~25
         26        IS_SMALLER_OR_EQUAL                                      ~26, !3
         27      > JMPZ                                                     ~27, ->36
   14    28    >   ASSIGN_OP                                     1          !6, 1
   15    29        INIT_FCALL                                               'date'
         30        SEND_VAL                                                 't'
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                         $29     
         33        MUL                                              ~30     $29, 86400
         34        ASSIGN_OP                                     1          !5, ~30
         35      > JMP                                                      ->46
   17    36    >   SUB                                              ~32     !3, !5
         37        IS_SMALLER_OR_EQUAL                                      86400, ~32
         38      > JMPZ                                                     ~33, ->45
   18    39    >   INIT_FCALL                                               'floor'
         40        SUB                                              ~34     !3, !5
         41        DIV                                              ~35     ~34, 86400
         42        SEND_VAL                                                 ~35
         43        DO_ICALL                                         $36     
         44        ASSIGN                                                   !7, $36
   21    45    > > JMP                                                      ->47
   12    46    > > JMPNZ                                                    <true>, ->20
   25    47    >   INIT_FCALL                                               'floor'
         48        DIV                                              ~38     !6, 12
         49        SEND_VAL                                                 ~38
         50        DO_ICALL                                         $39     
         51        ASSIGN                                                   !8, $39
   26    52        MOD                                              ~41     !6, 12
         53        ASSIGN                                                   !6, ~41
   28    54        INIT_FCALL                                               'floor'
         55        DIV                                              ~43     !4, 60
         56        DIV                                              ~44     ~43, 60
         57        MOD                                              ~45     ~44, 24
         58        SEND_VAL                                                 ~45
         59        DO_ICALL                                         $46     
         60        ASSIGN                                                   !9, $46
   29    61        INIT_FCALL                                               'floor'
         62        DIV                                              ~48     !4, 60
         63        MOD                                              ~49     ~48, 60
         64        SEND_VAL                                                 ~49
         65        DO_ICALL                                         $50     
         66        ASSIGN                                                   !10, $50
   30    67        MOD                                              ~52     !4, 60
         68        ASSIGN                                                   !11, ~52
   32    69        NEW                                              $54     'stdClass'
         70        DO_FCALL                                      0          
         71        ASSIGN                                                   !12, $54
   34    72        ASSIGN_OBJ                                               !12, 'y'
         73        OP_DATA                                                  !8
   35    74        ASSIGN_OBJ                                               !12, 'm'
         75        OP_DATA                                                  !6
   36    76        ASSIGN_OBJ                                               !12, 'd'
         77        OP_DATA                                                  !7
   37    78        ASSIGN_OBJ                                               !12, 'h'
         79        OP_DATA                                                  !9
   38    80        ASSIGN_OBJ                                               !12, 'i'
         81        OP_DATA                                                  !10
   39    82        ASSIGN_OBJ                                               !12, 's'
         83        OP_DATA                                                  !11
   40    84        INIT_FCALL                                               'floor'
         85        DIV                                              ~64     !4, 86400
         86        SEND_VAL                                                 ~64
         87        DO_ICALL                                         $65     
         88        ASSIGN_OBJ                                               !12, 'days'
         89        OP_DATA                                                  $65
   42    90      > RETURN                                                   !12
   43    91*     > RETURN                                                   null

End of function datediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157 ms | 1407 KiB | 20 Q