3v4l.org

run code in 300+ PHP versions simultaneously
<?php $now = new DateTime('now'); $expire_date = date('Y-m-d H:i:s', strtotime('+3 weeks')); $expire_on = new DateTime($expire_date); $time_left = $now->diff($expire_on); echo format_interval($time_left); function format_interval($time_left) { $format_string = ""; $weeks = (int) ($time_left->d / 7); $days = (int) ($time_left->d - ($weeks * 7)); if ($time_left->y > 0) $format_string = "%y year(s), %m month(s), $weeks week(s), $days day(s), %h hour(s) and %i minute(s)"; elseif ($time_left->m > 0) $format_string = "%m month(s), $weeks week(s), $days day(s), %h hour(s) and %i minute(s)"; elseif ($weeks > 0) $format_string = "$weeks week(s), $days day(s), %h hour(s) and %i minute(s)"; elseif ($time_left->d > 0) $format_string = "$days day(s), %h hour(s) and %i minute(s)"; elseif ($time_left->h > 0) $format_string = "%h hour(s) and %i minute(s)"; elseif ($time_left->i > 0) $format_string = "%i minute(s)"; else $format_string = "%s second(s)"; return $time_left->format($format_string); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BiYHD
function name:  (null)
number of ops:  25
compiled vars:  !0 = $now, !1 = $expire_date, !2 = $expire_on, !3 = $time_left
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $4      'DateTime'
          1        SEND_VAL_EX                                              'now'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $4
    4     4        INIT_FCALL                                               'date'
          5        SEND_VAL                                                 'Y-m-d+H%3Ai%3As'
          6        INIT_FCALL                                               'strtotime'
          7        SEND_VAL                                                 '%2B3+weeks'
          8        DO_ICALL                                         $7      
          9        SEND_VAR                                                 $7
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !1, $8
    5    12        NEW                                              $10     'DateTime'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !2, $10
    6    16        INIT_METHOD_CALL                                         !0, 'diff'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0  $13     
         19        ASSIGN                                                   !3, $13
    8    20        INIT_FCALL_BY_NAME                                       'format_interval'
         21        SEND_VAR_EX                                              !3
         22        DO_FCALL                                      0  $15     
         23        ECHO                                                     $15
   22    24      > RETURN                                                   1

Function format_interval:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 31
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BiYHD
function name:  format_interval
number of ops:  62
compiled vars:  !0 = $time_left, !1 = $format_string, !2 = $weeks, !3 = $days
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        ASSIGN                                                   !1, ''
   12     2        FETCH_OBJ_R                                      ~5      !0, 'd'
          3        DIV                                              ~6      ~5, 7
          4        CAST                                          4  ~7      ~6
          5        ASSIGN                                                   !2, ~7
   13     6        FETCH_OBJ_R                                      ~9      !0, 'd'
          7        MUL                                              ~10     !2, 7
          8        SUB                                              ~11     ~9, ~10
          9        CAST                                          4  ~12     ~11
         10        ASSIGN                                                   !3, ~12
   14    11        FETCH_OBJ_R                                      ~14     !0, 'y'
         12        IS_SMALLER                                               0, ~14
         13      > JMPZ                                                     ~15, ->21
         14    >   ROPE_INIT                                     5  ~17     '%25y+year%28s%29%2C+%25m+month%28s%29%2C+'
         15        ROPE_ADD                                      1  ~17     ~17, !2
         16        ROPE_ADD                                      2  ~17     ~17, '+week%28s%29%2C+'
         17        ROPE_ADD                                      3  ~17     ~17, !3
         18        ROPE_END                                      4  ~16     ~17, '+day%28s%29%2C+%25h+hour%28s%29+and+%25i+minute%28s%29'
         19        ASSIGN                                                   !1, ~16
         20      > JMP                                                      ->57
   15    21    >   FETCH_OBJ_R                                      ~21     !0, 'm'
         22        IS_SMALLER                                               0, ~21
         23      > JMPZ                                                     ~22, ->31
         24    >   ROPE_INIT                                     5  ~24     '%25m+month%28s%29%2C+'
         25        ROPE_ADD                                      1  ~24     ~24, !2
         26        ROPE_ADD                                      2  ~24     ~24, '+week%28s%29%2C+'
         27        ROPE_ADD                                      3  ~24     ~24, !3
         28        ROPE_END                                      4  ~23     ~24, '+day%28s%29%2C+%25h+hour%28s%29+and+%25i+minute%28s%29'
         29        ASSIGN                                                   !1, ~23
         30      > JMP                                                      ->57
   16    31    >   IS_SMALLER                                               0, !2
         32      > JMPZ                                                     ~28, ->39
         33    >   ROPE_INIT                                     4  ~30     !2
         34        ROPE_ADD                                      1  ~30     ~30, '+week%28s%29%2C+'
         35        ROPE_ADD                                      2  ~30     ~30, !3
         36        ROPE_END                                      3  ~29     ~30, '+day%28s%29%2C+%25h+hour%28s%29+and+%25i+minute%28s%29'
         37        ASSIGN                                                   !1, ~29
         38      > JMP                                                      ->57
   17    39    >   FETCH_OBJ_R                                      ~33     !0, 'd'
         40        IS_SMALLER                                               0, ~33
         41      > JMPZ                                                     ~34, ->46
         42    >   NOP                                                      
         43        FAST_CONCAT                                      ~35     !3, '+day%28s%29%2C+%25h+hour%28s%29+and+%25i+minute%28s%29'
         44        ASSIGN                                                   !1, ~35
         45      > JMP                                                      ->57
   18    46    >   FETCH_OBJ_R                                      ~37     !0, 'h'
         47        IS_SMALLER                                               0, ~37
         48      > JMPZ                                                     ~38, ->51
         49    >   ASSIGN                                                   !1, '%25h+hour%28s%29+and+%25i+minute%28s%29'
         50      > JMP                                                      ->57
   19    51    >   FETCH_OBJ_R                                      ~40     !0, 'i'
         52        IS_SMALLER                                               0, ~40
         53      > JMPZ                                                     ~41, ->56
         54    >   ASSIGN                                                   !1, '%25i+minute%28s%29'
         55      > JMP                                                      ->57
   20    56    >   ASSIGN                                                   !1, '%25s+second%28s%29'
   21    57    >   INIT_METHOD_CALL                                         !0, 'format'
         58        SEND_VAR_EX                                              !1
         59        DO_FCALL                                      0  $44     
         60      > RETURN                                                   $44
   22    61*     > RETURN                                                   null

End of function format_interval

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
208.76 ms | 1012 KiB | 15 Q