3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getDiffInHours(\DateTime $earlierDate, \DateTime $laterDate) { $utc = new \DateTimeZone('UTC'); //First convert to UTC to avoid missing hours due to DST etc $earlierDate->setTimezone($utc); $laterDate->setTimezone($utc); $diff = $earlierDate->diff($laterDate); return 24 * $diff->days + $diff->h; } $earlierDate = new \DateTime(); $laterDate = new \DateTime('+ 31 hours'); $hours = getDiffInHours($earlierTime, $laterTime); var_dump($hours, $earlierTime, $laterTime);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GEJS0
function name:  (null)
number of ops:  18
compiled vars:  !0 = $earlierDate, !1 = $laterDate, !2 = $hours, !3 = $earlierTime, !4 = $laterTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $5      'DateTime'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $5
   13     3        NEW                                              $8      'DateTime'
          4        SEND_VAL_EX                                              '%2B+31+hours'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $8
   15     7        INIT_FCALL                                               'getdiffinhours'
          8        SEND_VAR                                                 !3
          9        SEND_VAR                                                 !4
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !2, $11
   16    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !3
         15        SEND_VAR                                                 !4
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function getdiffinhours:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GEJS0
function name:  getDiffInHours
number of ops:  22
compiled vars:  !0 = $earlierDate, !1 = $laterDate, !2 = $utc, !3 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        NEW                                              $4      'DateTimeZone'
          3        SEND_VAL_EX                                              'UTC'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $4
    6     6        INIT_METHOD_CALL                                         !0, 'setTimezone'
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0          
    7     9        INIT_METHOD_CALL                                         !1, 'setTimezone'
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0          
    8    12        INIT_METHOD_CALL                                         !0, 'diff'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !3, $9
    9    16        FETCH_OBJ_R                                      ~11     !3, 'days'
         17        MUL                                              ~12     ~11, 24
         18        FETCH_OBJ_R                                      ~13     !3, 'h'
         19        ADD                                              ~14     ~12, ~13
         20      > RETURN                                                   ~14
   10    21*     > RETURN                                                   null

End of function getdiffinhours

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.69 ms | 1403 KiB | 16 Q