3v4l.org

run code in 300+ PHP versions simultaneously
<?php function secondsToTime($seconds) { $dtF = new \DateTime('@0'); $dtT = new \DateTime("@$seconds"); $diff = $dtF->diff($dtT); $units = [ 'y' => 'year', 'm' => 'month', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second' ]; foreach ($units as $char => $unit) { if ($diff->$char) { if ($char === 'd' && $diff->$char >= 7) { $diff->$char = floor($diff->$char / 7); $unit = 'week'; } return sprintf( '%d %s%s ago', $diff->$char, $unit, $diff->$char !== 1 ? 's' : '' ); } } } $tests = [ 53 => 53, // y=0, m=0, d=0, h=0, i=0, s=53 365 => 365, // y=0, m=0, d=0, h=0, i=6, s=5 7200 => 7200, // y=0, m=0, d=0, h=2, i=0, s=0 176455 => 176455, // y=0, m=0, d=2, h=1, i=0, s=55 2002000 => 2002000, // y=0, m=0, d=23, h=4, i=6, s=40 4592000 => 4592000, // y=0, m=1, d=22, h=3, i=33, s=20 66536000 => 66536000 // y=2, m=1, d=9, h=2, i=13, s=20 ]; var_export(array_map('secondsToTime',$tests));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CNq7v
function name:  (null)
number of ops:  9
compiled vars:  !0 = $tests
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, <array>
   41     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'array_map'
          3        SEND_VAL                                                 'secondsToTime'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function secondstotime:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 51
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 51
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 50
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 26
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
filename:       /in/CNq7v
function name:  secondsToTime
number of ops:  53
compiled vars:  !0 = $seconds, !1 = $dtF, !2 = $dtT, !3 = $diff, !4 = $units, !5 = $unit, !6 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        NEW                                              $7      'DateTime'
          2        SEND_VAL_EX                                              '%400'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $7
    5     5        NEW                                              $10     'DateTime'
          6        NOP                                                      
          7        FAST_CONCAT                                      ~11     '%40', !0
          8        SEND_VAL_EX                                              ~11
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $10
    6    11        INIT_METHOD_CALL                                         !1, 'diff'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0  $14     
         14        ASSIGN                                                   !3, $14
    7    15        ASSIGN                                                   !4, <array>
   15    16      > FE_RESET_R                                       $17     !4, ->51
         17    > > FE_FETCH_R                                       ~18     $17, !5, ->51
         18    >   ASSIGN                                                   !6, ~18
   16    19        FETCH_OBJ_R                                      ~20     !3, !6
         20      > JMPZ                                                     ~20, ->50
   17    21    >   IS_IDENTICAL                                     ~21     !6, 'd'
         22      > JMPZ_EX                                          ~21     ~21, ->26
         23    >   FETCH_OBJ_R                                      ~22     !3, !6
         24        IS_SMALLER_OR_EQUAL                              ~23     7, ~22
         25        BOOL                                             ~21     ~23
         26    > > JMPZ                                                     ~21, ->35
   18    27    >   INIT_FCALL                                               'floor'
         28        FETCH_OBJ_R                                      ~25     !3, !6
         29        DIV                                              ~26     ~25, 7
         30        SEND_VAL                                                 ~26
         31        DO_ICALL                                         $27     
         32        ASSIGN_OBJ                                               !3, !6
         33        OP_DATA                                                  $27
   19    34        ASSIGN                                                   !5, 'week'
   21    35    >   INIT_FCALL                                               'sprintf'
   22    36        SEND_VAL                                                 '%25d+%25s%25s+ago'
   23    37        FETCH_OBJ_R                                      ~29     !3, !6
         38        SEND_VAL                                                 ~29
   24    39        SEND_VAR                                                 !5
   25    40        FETCH_OBJ_R                                      ~30     !3, !6
         41        IS_NOT_IDENTICAL                                         ~30, 1
         42      > JMPZ                                                     ~31, ->45
         43    >   QM_ASSIGN                                        ~32     's'
         44      > JMP                                                      ->46
         45    >   QM_ASSIGN                                        ~32     ''
         46    >   SEND_VAL                                                 ~32
         47        DO_ICALL                                         $33     
         48        FE_FREE                                                  $17
         49      > RETURN                                                   $33
   15    50    > > JMP                                                      ->17
         51    >   FE_FREE                                                  $17
   29    52      > RETURN                                                   null

End of function secondstotime

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
213.16 ms | 1400 KiB | 21 Q