3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dt = new StdClass; $dt->now = new DateTime(); $occurredOn = new DateTime(); $dt->lastUpdated = $occurredOn; $dt->remainingHours = $occurredOn; $dt->interval = $dt->now->diff($dt->lastUpdated); $dt->remainingHours->add(new DateInterval("PT4H")); $dt->remainingHours = $dt->remainingHours->diff($dt->now); $dt->remainingHours = timeRemainingInFourHours($dt->remainingHours); $dt->title = formatDateInterval($dt->interval); function timeRemainingInFourHours(DateInterval $interval) { $hours = ""; $minutes = ""; if ($interval->h) { $hours = $interval->format("%h") . " hours"; } if ($interval->i) { $minutes = $interval->format("%i") . " minutes"; } return $hours . $minutes . ' remaining'; } function formatDateInterval(DateInterval $interval) { $result = ""; // ternary? if ($interval->y) { $result .= $interval->format("%y years "); } if ($interval->m) { $result .= $interval->format("%m months "); } if ($interval->d) { $result .= $interval->format("%d days "); } if ($interval->h) { $result .= $interval->format("%h hours "); } if ($interval->i) { $result .= $interval->format("%i minutes "); } if ($interval->s) { $result .= $interval->format("%s seconds "); } else { $result .= "hot off the press"; } return $result; } var_dump($dt);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IV3eT
function name:  (null)
number of ops:  55
compiled vars:  !0 = $dt, !1 = $occurredOn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $2      'StdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
    4     3        NEW                                              $6      'DateTime'
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               !0, 'now'
          6        OP_DATA                                                  $6
    6     7        NEW                                              $8      'DateTime'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $8
    8    10        ASSIGN_OBJ                                               !0, 'lastUpdated'
         11        OP_DATA                                                  !1
    9    12        ASSIGN_OBJ                                               !0, 'remainingHours'
         13        OP_DATA                                                  !1
   11    14        FETCH_OBJ_R                                      ~14     !0, 'now'
         15        INIT_METHOD_CALL                                         ~14, 'diff'
         16        CHECK_FUNC_ARG                                           
         17        FETCH_OBJ_FUNC_ARG                               $15     !0, 'lastUpdated'
         18        SEND_FUNC_ARG                                            $15
         19        DO_FCALL                                      0  $16     
         20        ASSIGN_OBJ                                               !0, 'interval'
         21        OP_DATA                                                  $16
   13    22        FETCH_OBJ_R                                      ~17     !0, 'remainingHours'
         23        INIT_METHOD_CALL                                         ~17, 'add'
         24        NEW                                              $18     'DateInterval'
         25        SEND_VAL_EX                                              'PT4H'
         26        DO_FCALL                                      0          
         27        SEND_VAR_NO_REF_EX                                       $18
         28        DO_FCALL                                      0          
   15    29        FETCH_OBJ_R                                      ~22     !0, 'remainingHours'
         30        INIT_METHOD_CALL                                         ~22, 'diff'
         31        CHECK_FUNC_ARG                                           
         32        FETCH_OBJ_FUNC_ARG                               $23     !0, 'now'
         33        SEND_FUNC_ARG                                            $23
         34        DO_FCALL                                      0  $24     
         35        ASSIGN_OBJ                                               !0, 'remainingHours'
         36        OP_DATA                                                  $24
   16    37        INIT_FCALL_BY_NAME                                       'timeRemainingInFourHours'
         38        CHECK_FUNC_ARG                                           
         39        FETCH_OBJ_FUNC_ARG                               $26     !0, 'remainingHours'
         40        SEND_FUNC_ARG                                            $26
         41        DO_FCALL                                      0  $27     
         42        ASSIGN_OBJ                                               !0, 'remainingHours'
         43        OP_DATA                                                  $27
   17    44        INIT_FCALL_BY_NAME                                       'formatDateInterval'
         45        CHECK_FUNC_ARG                                           
         46        FETCH_OBJ_FUNC_ARG                               $29     !0, 'interval'
         47        SEND_FUNC_ARG                                            $29
         48        DO_FCALL                                      0  $30     
         49        ASSIGN_OBJ                                               !0, 'title'
         50        OP_DATA                                                  $30
   61    51        INIT_FCALL                                               'var_dump'
         52        SEND_VAR                                                 !0
         53        DO_ICALL                                                 
         54      > RETURN                                                   1

Function timeremaininginfourhours:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 10
filename:       /in/IV3eT
function name:  timeRemainingInFourHours
number of ops:  21
compiled vars:  !0 = $interval, !1 = $hours, !2 = $minutes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, ''
   24     2        ASSIGN                                                   !2, ''
   26     3        FETCH_OBJ_R                                      ~5      !0, 'h'
          4      > JMPZ                                                     ~5, ->10
          5    >   INIT_METHOD_CALL                                         !0, 'format'
          6        SEND_VAL_EX                                              '%25h'
          7        DO_FCALL                                      0  $6      
          8        CONCAT                                           ~7      $6, '+hours'
          9        ASSIGN                                                   !1, ~7
   28    10    >   FETCH_OBJ_R                                      ~9      !0, 'i'
         11      > JMPZ                                                     ~9, ->17
         12    >   INIT_METHOD_CALL                                         !0, 'format'
         13        SEND_VAL_EX                                              '%25i'
         14        DO_FCALL                                      0  $10     
         15        CONCAT                                           ~11     $10, '+minutes'
         16        ASSIGN                                                   !2, ~11
   32    17    >   CONCAT                                           ~13     !1, !2
         18        CONCAT                                           ~14     ~13, '+remaining'
         19      > RETURN                                                   ~14
   34    20*     > RETURN                                                   null

End of function timeremaininginfourhours

Function formatdateinterval:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 39
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 26
Branch analysis from position: 20
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/IV3eT
function name:  formatDateInterval
number of ops:  42
compiled vars:  !0 = $interval, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   39     1        ASSIGN                                                   !1, ''
   43     2        FETCH_OBJ_R                                      ~3      !0, 'y'
          3      > JMPZ                                                     ~3, ->8
          4    >   INIT_METHOD_CALL                                         !0, 'format'
          5        SEND_VAL_EX                                              '%25y+years+'
          6        DO_FCALL                                      0  $4      
          7        ASSIGN_OP                                     8          !1, $4
   45     8    >   FETCH_OBJ_R                                      ~6      !0, 'm'
          9      > JMPZ                                                     ~6, ->14
         10    >   INIT_METHOD_CALL                                         !0, 'format'
         11        SEND_VAL_EX                                              '%25m+months+'
         12        DO_FCALL                                      0  $7      
         13        ASSIGN_OP                                     8          !1, $7
   47    14    >   FETCH_OBJ_R                                      ~9      !0, 'd'
         15      > JMPZ                                                     ~9, ->20
         16    >   INIT_METHOD_CALL                                         !0, 'format'
         17        SEND_VAL_EX                                              '%25d+days+'
         18        DO_FCALL                                      0  $10     
         19        ASSIGN_OP                                     8          !1, $10
   49    20    >   FETCH_OBJ_R                                      ~12     !0, 'h'
         21      > JMPZ                                                     ~12, ->26
         22    >   INIT_METHOD_CALL                                         !0, 'format'
         23        SEND_VAL_EX                                              '%25h+hours+'
         24        DO_FCALL                                      0  $13     
         25        ASSIGN_OP                                     8          !1, $13
   51    26    >   FETCH_OBJ_R                                      ~15     !0, 'i'
         27      > JMPZ                                                     ~15, ->32
         28    >   INIT_METHOD_CALL                                         !0, 'format'
         29        SEND_VAL_EX                                              '%25i+minutes+'
         30        DO_FCALL                                      0  $16     
         31        ASSIGN_OP                                     8          !1, $16
   53    32    >   FETCH_OBJ_R                                      ~18     !0, 's'
         33      > JMPZ                                                     ~18, ->39
         34    >   INIT_METHOD_CALL                                         !0, 'format'
         35        SEND_VAL_EX                                              '%25s+seconds+'
         36        DO_FCALL                                      0  $19     
         37        ASSIGN_OP                                     8          !1, $19
         38      > JMP                                                      ->40
   55    39    >   ASSIGN_OP                                     8          !1, 'hot+off+the+press'
   57    40    > > RETURN                                                   !1
   59    41*     > RETURN                                                   null

End of function formatdateinterval

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.64 ms | 1400 KiB | 15 Q