3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createFromInput(string $input, string $lang){ $inputFormat = ['en' => 'm/d/Y H:i:s', 'fr' => 'd/m/Y H:i:s', 'de' => 'd.m.Y H:i:s']; return DateTime::createFromFormat($inputFormat[$lang],$input); } $lang = 'en'; $input = '12/20/2022 10:20:20'; echo createFromInput($input, $lang)->format('Y-m-d H:i:s'); //2022-12-20 10:20:20 $lang = 'fr'; $input = '20/12/2022 10:20:20'; echo createFromInput($input, $lang)->format('Y-m-d H:i:s'); //2022-12-20 10:20:20
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q3hoA
function name:  (null)
number of ops:  21
compiled vars:  !0 = $lang, !1 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, 'en'
    8     1        ASSIGN                                                   !1, '12%2F20%2F2022+10%3A20%3A20'
    9     2        INIT_FCALL                                               'createfrominput'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        INIT_METHOD_CALL                                         $4, 'format'
          7        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
          8        DO_FCALL                                      0  $5      
          9        ECHO                                                     $5
   12    10        ASSIGN                                                   !0, 'fr'
   13    11        ASSIGN                                                   !1, '20%2F12%2F2022+10%3A20%3A20'
   14    12        INIT_FCALL                                               'createfrominput'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0  $8      
         16        INIT_METHOD_CALL                                         $8, 'format'
         17        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As'
         18        DO_FCALL                                      0  $9      
         19        ECHO                                                     $9
   15    20      > RETURN                                                   1

Function createfrominput:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q3hoA
function name:  createFromInput
number of ops:  10
compiled vars:  !0 = $input, !1 = $lang, !2 = $inputFormat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    4     3        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          4        FETCH_DIM_R                                      ~4      !2, !1
          5        SEND_VAL                                                 ~4
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $5      
          8      > RETURN                                                   $5
    5     9*     > RETURN                                                   null

End of function createfrominput

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.68 ms | 1001 KiB | 15 Q