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

End of function datediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.49 ms | 1415 KiB | 22 Q