3v4l.org

run code in 500+ PHP versions simultaneously
<?php function convert_uk_reg_year_to_yyyy($year) { // Normalise year to padded with 1 leading zero, if necessary. This ensures that // if the input is int(9) instead of string(2) "09" then it will still work as // expected. $year = str_pad((int)$year, 2, 0, STR_PAD_LEFT); // Make sure input is within valid range if ($year < 0 || $year > 99) { return false; } // Create result return "20" . ($year[0] % 5) . $year[1]; } // given examples var_dump(convert_uk_reg_year_to_yyyy(55)); var_dump(convert_uk_reg_year_to_yyyy(03)); var_dump(convert_uk_reg_year_to_yyyy(62)); // future plates var_dump(convert_uk_reg_year_to_yyyy(17)); // 2017 var_dump(convert_uk_reg_year_to_yyyy(22)); // 2022 var_dump(convert_uk_reg_year_to_yyyy(72)); // 2022 // invalid input var_dump(convert_uk_reg_year_to_yyyy(101)); var_dump(convert_uk_reg_year_to_yyyy(-1)); var_dump(convert_uk_reg_year_to_yyyy(999));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TglmD
function name:  (null)
number of ops:  55
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
          2        SEND_VAL                                                     55
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
          5        DO_ICALL                                                     
   21     6        INIT_FCALL                                                   'var_dump'
          7        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
          8        SEND_VAL                                                     3
          9        DO_FCALL                                          0  $2      
         10        SEND_VAR                                                     $2
         11        DO_ICALL                                                     
   22    12        INIT_FCALL                                                   'var_dump'
         13        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
         14        SEND_VAL                                                     62
         15        DO_FCALL                                          0  $4      
         16        SEND_VAR                                                     $4
         17        DO_ICALL                                                     
   25    18        INIT_FCALL                                                   'var_dump'
         19        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
         20        SEND_VAL                                                     17
         21        DO_FCALL                                          0  $6      
         22        SEND_VAR                                                     $6
         23        DO_ICALL                                                     
   26    24        INIT_FCALL                                                   'var_dump'
         25        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
         26        SEND_VAL                                                     22
         27        DO_FCALL                                          0  $8      
         28        SEND_VAR                                                     $8
         29        DO_ICALL                                                     
   27    30        INIT_FCALL                                                   'var_dump'
         31        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
         32        SEND_VAL                                                     72
         33        DO_FCALL                                          0  $10     
         34        SEND_VAR                                                     $10
         35        DO_ICALL                                                     
   30    36        INIT_FCALL                                                   'var_dump'
         37        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
         38        SEND_VAL                                                     101
         39        DO_FCALL                                          0  $12     
         40        SEND_VAR                                                     $12
         41        DO_ICALL                                                     
   31    42        INIT_FCALL                                                   'var_dump'
         43        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
         44        SEND_VAL                                                     -1
         45        DO_FCALL                                          0  $14     
         46        SEND_VAR                                                     $14
         47        DO_ICALL                                                     
   32    48        INIT_FCALL                                                   'var_dump'
         49        INIT_FCALL                                                   'convert_uk_reg_year_to_yyyy'
         50        SEND_VAL                                                     999
         51        DO_FCALL                                          0  $16     
         52        SEND_VAR                                                     $16
         53        DO_ICALL                                                     
         54      > RETURN                                                       1

Function convert_uk_reg_year_to_yyyy:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/TglmD
function name:  convert_uk_reg_year_to_yyyy
number of ops:  22
compiled vars:  !0 = $year
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    8     1        INIT_FCALL                                                   'str_pad'
          2        CAST                                              4  ~1      !0
          3        SEND_VAL                                                     ~1
          4        SEND_VAL                                                     2
          5        SEND_VAL                                                     0
          6        SEND_VAL                                                     0
          7        DO_ICALL                                             $2      
          8        ASSIGN                                                       !0, $2
   11     9        IS_SMALLER                                           ~4      !0, 0
         10      > JMPNZ_EX                                             ~4      ~4, ->13
         11    >   IS_SMALLER                                           ~5      99, !0
         12        BOOL                                                 ~4      ~5
         13    > > JMPZ                                                         ~4, ->15
   12    14    > > RETURN                                                       <false>
   16    15    >   FETCH_DIM_R                                          ~6      !0, 0
         16        MOD                                                  ~7      ~6, 5
         17        CONCAT                                               ~8      '20', ~7
         18        FETCH_DIM_R                                          ~9      !0, 1
         19        CONCAT                                               ~10     ~8, ~9
         20      > RETURN                                                       ~10
   17    21*     > RETURN                                                       null

End of function convert_uk_reg_year_to_yyyy

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.08 ms | 2681 KiB | 24 Q