3v4l.org

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

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

End of function getdiffinhours

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.23 ms | 948 KiB | 17 Q