3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Smarty plugin * ------------------------------------------------------------- * File: modifier.age.php * Type: modifier * Name: age * Purpose: Calculate the age of a string date * ------------------------------------------------------------- * @author Gabriel Heming * @param string $date Input date string * @param string $format Input date string format * @return int */ function smarty_modifier_age($date , $format = 'Y-m-d') { if(!$dateTime = DateTime::createFromFormat($format , $date)) { throw new \RuntimeException('Invalid Date format'); } return (int)($dateTime->diff(new \DateTime() , true)->format('%y')); } echo smarty_modifier_calculate_age('2000-01-01');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KpOch
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL_BY_NAME                                       'smarty_modifier_calculate_age'
          1        SEND_VAL_EX                                              '2000-01-01'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function smarty_modifier_age:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KpOch
function name:  smarty_modifier_age
number of ops:  25
compiled vars:  !0 = $date, !1 = $format, !2 = $dateTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'Y-m-d'
   18     2        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                           ~4      !2, $3
          7        BOOL_NOT                                         ~5      ~4
          8      > JMPZ                                                     ~5, ->13
   20     9    >   NEW                                              $6      'RuntimeException'
         10        SEND_VAL_EX                                              'Invalid+Date+format'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $6
   23    13    >   INIT_METHOD_CALL                                         !2, 'diff'
         14        NEW                                              $8      'DateTime'
         15        DO_FCALL                                      0          
         16        SEND_VAR_NO_REF_EX                                       $8
         17        SEND_VAL_EX                                              <true>
         18        DO_FCALL                                      0  $10     
         19        INIT_METHOD_CALL                                         $10, 'format'
         20        SEND_VAL_EX                                              '%25y'
         21        DO_FCALL                                      0  $11     
         22        CAST                                          4  ~12     $11
         23      > RETURN                                                   ~12
   24    24*     > RETURN                                                   null

End of function smarty_modifier_age

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.25 ms | 1014 KiB | 13 Q