3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_age($date, $units='years') { $modifier = date('n') - date('n', strtotime($date)) ? 1 : (date('j') - date('j', strtotime($date)) ? 1 : 0); $seconds = (time()-strtotime($date)); $years = (date('Y')-date('Y', strtotime($date))-$modifier); switch($units) { case 'seconds': return $seconds; case 'minutes': return round($seconds/60); case 'hours': return round($seconds/60/60); case 'days': return round($seconds/60/60/24); case 'months': return ($years*12+date('n')); case 'decades': return ($years/10); case 'centuries': return ($years/100); case 'years': default: return $years; } } echo 'I am '.get_age('September 19th, 1984', 'days').' days old';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GU1ni
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'get_age'
          1        SEND_VAL                                                 'September+19th%2C+1984'
          2        SEND_VAL                                                 'days'
          3        DO_FCALL                                      0  $0      
          4        CONCAT                                           ~1      'I+am+', $0
          5        CONCAT                                           ~2      ~1, '+days+old'
          6        ECHO                                                     ~2
          7      > RETURN                                                   1

Function get_age:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
10 jumps found. (Code = 188) Position 1 = 71, Position 2 = 72, Position 3 = 77, Position 4 = 83, Position 5 = 90, Position 6 = 96, Position 7 = 98, Position 8 = 100, Position 9 = 100, Position 10 = 54
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 83
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 96
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 98
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 100
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 100
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 71
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 72
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 77
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 83
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 90
Branch analysis from position: 64
2 jumps found. (Code = 44) Position 1 = 66, Position 2 = 96
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 98
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 100
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 100
Branch analysis from position: 100
Branch analysis from position: 100
Branch analysis from position: 98
Branch analysis from position: 96
Branch analysis from position: 90
Branch analysis from position: 83
Branch analysis from position: 77
Branch analysis from position: 72
Branch analysis from position: 71
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
10 jumps found. (Code = 188) Position 1 = 71, Position 2 = 72, Position 3 = 77, Position 4 = 83, Position 5 = 90, Position 6 = 96, Position 7 = 98, Position 8 = 100, Position 9 = 100, Position 10 = 54
Branch analysis from position: 71
Branch analysis from position: 72
Branch analysis from position: 77
Branch analysis from position: 83
Branch analysis from position: 90
Branch analysis from position: 96
Branch analysis from position: 98
Branch analysis from position: 100
Branch analysis from position: 100
Branch analysis from position: 54
Branch analysis from position: 30
10 jumps found. (Code = 188) Position 1 = 71, Position 2 = 72, Position 3 = 77, Position 4 = 83, Position 5 = 90, Position 6 = 96, Position 7 = 98, Position 8 = 100, Position 9 = 100, Position 10 = 54
Branch analysis from position: 71
Branch analysis from position: 72
Branch analysis from position: 77
Branch analysis from position: 83
Branch analysis from position: 90
Branch analysis from position: 96
Branch analysis from position: 98
Branch analysis from position: 100
Branch analysis from position: 100
Branch analysis from position: 54
filename:       /in/GU1ni
function name:  get_age
number of ops:  102
compiled vars:  !0 = $date, !1 = $units, !2 = $modifier, !3 = $seconds, !4 = $years
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'years'
    4     2        INIT_FCALL                                               'date'
          3        SEND_VAL                                                 'n'
          4        DO_ICALL                                         $5      
          5        INIT_FCALL                                               'date'
          6        SEND_VAL                                                 'n'
          7        INIT_FCALL                                               'strtotime'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        SUB                                              ~8      $5, $7
         13      > JMPZ                                                     ~8, ->16
         14    >   QM_ASSIGN                                        ~9      1
         15      > JMP                                                      ->32
         16    >   INIT_FCALL                                               'date'
         17        SEND_VAL                                                 'j'
         18        DO_ICALL                                         $10     
         19        INIT_FCALL                                               'date'
         20        SEND_VAL                                                 'j'
         21        INIT_FCALL                                               'strtotime'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $11     
         24        SEND_VAR                                                 $11
         25        DO_ICALL                                         $12     
         26        SUB                                              ~13     $10, $12
         27      > JMPZ                                                     ~13, ->30
         28    >   QM_ASSIGN                                        ~14     1
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~14     0
         31    >   QM_ASSIGN                                        ~9      ~14
         32    >   ASSIGN                                                   !2, ~9
    5    33        INIT_FCALL                                               'time'
         34        DO_ICALL                                         $16     
         35        INIT_FCALL                                               'strtotime'
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $17     
         38        SUB                                              ~18     $16, $17
         39        ASSIGN                                                   !3, ~18
    6    40        INIT_FCALL                                               'date'
         41        SEND_VAL                                                 'Y'
         42        DO_ICALL                                         $20     
         43        INIT_FCALL                                               'date'
         44        SEND_VAL                                                 'Y'
         45        INIT_FCALL                                               'strtotime'
         46        SEND_VAR                                                 !0
         47        DO_ICALL                                         $21     
         48        SEND_VAR                                                 $21
         49        DO_ICALL                                         $22     
         50        SUB                                              ~23     $20, $22
         51        SUB                                              ~24     ~23, !2
         52        ASSIGN                                                   !4, ~24
    7    53      > SWITCH_STRING                                            !1, [ 'seconds':->71, 'minutes':->72, 'hours':->77, 'days':->83, 'months':->90, 'decades':->96, 'centuries':->98, 'years':->100, ], ->100
    9    54    >   IS_EQUAL                                                 !1, 'seconds'
         55      > JMPNZ                                                    ~26, ->71
   11    56    >   IS_EQUAL                                                 !1, 'minutes'
         57      > JMPNZ                                                    ~26, ->72
   13    58    >   IS_EQUAL                                                 !1, 'hours'
         59      > JMPNZ                                                    ~26, ->77
   15    60    >   IS_EQUAL                                                 !1, 'days'
         61      > JMPNZ                                                    ~26, ->83
   17    62    >   IS_EQUAL                                                 !1, 'months'
         63      > JMPNZ                                                    ~26, ->90
   19    64    >   IS_EQUAL                                                 !1, 'decades'
         65      > JMPNZ                                                    ~26, ->96
   21    66    >   IS_EQUAL                                                 !1, 'centuries'
         67      > JMPNZ                                                    ~26, ->98
   23    68    >   IS_EQUAL                                                 !1, 'years'
         69      > JMPNZ                                                    ~26, ->100
         70    > > JMP                                                      ->100
   10    71    > > RETURN                                                   !3
   12    72    >   INIT_FCALL                                               'round'
         73        DIV                                              ~27     !3, 60
         74        SEND_VAL                                                 ~27
         75        DO_ICALL                                         $28     
         76      > RETURN                                                   $28
   14    77    >   INIT_FCALL                                               'round'
         78        DIV                                              ~29     !3, 60
         79        DIV                                              ~30     ~29, 60
         80        SEND_VAL                                                 ~30
         81        DO_ICALL                                         $31     
         82      > RETURN                                                   $31
   16    83    >   INIT_FCALL                                               'round'
         84        DIV                                              ~32     !3, 60
         85        DIV                                              ~33     ~32, 60
         86        DIV                                              ~34     ~33, 24
         87        SEND_VAL                                                 ~34
         88        DO_ICALL                                         $35     
         89      > RETURN                                                   $35
   18    90    >   MUL                                              ~36     !4, 12
         91        INIT_FCALL                                               'date'
         92        SEND_VAL                                                 'n'
         93        DO_ICALL                                         $37     
         94        ADD                                              ~38     ~36, $37
         95      > RETURN                                                   ~38
   20    96    >   DIV                                              ~39     !4, 10
         97      > RETURN                                                   ~39
   22    98    >   DIV                                              ~40     !4, 100
         99      > RETURN                                                   ~40
   25   100    > > RETURN                                                   !4
   27   101*     > RETURN                                                   null

End of function get_age

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.52 ms | 1415 KiB | 22 Q