3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dt = new StdClass; $dt->now = new DateTime(); $occurredOn = new DateTime('2014-09-23'); // new DateTime(); $dt->lastUpdated = $occurredOn; $dt->interval = $dt->now->diff($dt->lastUpdated); $dt->remainingHours = $occurredOn; $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/4IQjQ
function name:  (null)
number of ops:  56
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        SEND_VAL_EX                                              '2014-09-23'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $8
    8    11        ASSIGN_OBJ                                               !0, 'lastUpdated'
         12        OP_DATA                                                  !1
   10    13        FETCH_OBJ_R                                      ~13     !0, 'now'
         14        INIT_METHOD_CALL                                         ~13, 'diff'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_OBJ_FUNC_ARG                               $14     !0, 'lastUpdated'
         17        SEND_FUNC_ARG                                            $14
         18        DO_FCALL                                      0  $15     
         19        ASSIGN_OBJ                                               !0, 'interval'
         20        OP_DATA                                                  $15
   12    21        ASSIGN_OBJ                                               !0, 'remainingHours'
         22        OP_DATA                                                  !1
   17    23        FETCH_OBJ_R                                      ~17     !0, 'remainingHours'
         24        INIT_METHOD_CALL                                         ~17, 'add'
         25        NEW                                              $18     'DateInterval'
         26        SEND_VAL_EX                                              'PT4H'
         27        DO_FCALL                                      0          
         28        SEND_VAR_NO_REF_EX                                       $18
         29        DO_FCALL                                      0          
   19    30        FETCH_OBJ_R                                      ~22     !0, 'remainingHours'
         31        INIT_METHOD_CALL                                         ~22, 'diff'
         32        CHECK_FUNC_ARG                                           
         33        FETCH_OBJ_FUNC_ARG                               $23     !0, 'now'
         34        SEND_FUNC_ARG                                            $23
         35        DO_FCALL                                      0  $24     
         36        ASSIGN_OBJ                                               !0, 'remainingHours'
         37        OP_DATA                                                  $24
   20    38        INIT_FCALL_BY_NAME                                       'timeRemainingInFourHours'
         39        CHECK_FUNC_ARG                                           
         40        FETCH_OBJ_FUNC_ARG                               $26     !0, 'remainingHours'
         41        SEND_FUNC_ARG                                            $26
         42        DO_FCALL                                      0  $27     
         43        ASSIGN_OBJ                                               !0, 'remainingHours'
         44        OP_DATA                                                  $27
   21    45        INIT_FCALL_BY_NAME                                       'formatDateInterval'
         46        CHECK_FUNC_ARG                                           
         47        FETCH_OBJ_FUNC_ARG                               $29     !0, 'interval'
         48        SEND_FUNC_ARG                                            $29
         49        DO_FCALL                                      0  $30     
         50        ASSIGN_OBJ                                               !0, 'title'
         51        OP_DATA                                                  $30
   65    52        INIT_FCALL                                               'var_dump'
         53        SEND_VAR                                                 !0
         54        DO_ICALL                                                 
         55      > 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/4IQjQ
function name:  timeRemainingInFourHours
number of ops:  21
compiled vars:  !0 = $interval, !1 = $hours, !2 = $minutes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   26     1        ASSIGN                                                   !1, ''
   28     2        ASSIGN                                                   !2, ''
   30     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
   32    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
   36    17    >   CONCAT                                           ~13     !1, !2
         18        CONCAT                                           ~14     ~13, '+remaining'
         19      > RETURN                                                   ~14
   38    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/4IQjQ
function name:  formatDateInterval
number of ops:  42
compiled vars:  !0 = $interval, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   43     1        ASSIGN                                                   !1, ''
   47     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
   49     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
   51    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
   53    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
   55    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
   57    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
   59    39    >   ASSIGN_OP                                     8          !1, 'hot+off+the+press'
   61    40    > > RETURN                                                   !1
   63    41*     > RETURN                                                   null

End of function formatdateinterval

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.36 ms | 1408 KiB | 15 Q