3v4l.org

run code in 300+ PHP versions simultaneously
<?php function saveCityZipCode(string $city, string $zipCode): void { var_dump($city, $zipCode); } $address = 'Studio 5, One Infinite Loop, Cupertino 95014'; preg_match('/\s*([^,]+?)\s*(\d+)$/', $address, $m) or throw new Exception('Failed to parse city and zipcode of address'); saveCityZipCode(...array_slice($m, 1)); // or just saveCityZipCode($m[1], $m[2]); // named capture groups can be spread too (but I probably wouldn't until PHP makes a PREG_NO_INDEXED_KEYS flag). echo "\n---\n"; preg_match('/\s*(?<city>[^,]+?)\s*(?<zipCode>\d+)$/', $address, $m) or throw new Exception('Failed to parse city and zipcode of address'); saveCityZipCode(...array_filter($m, fn($k) => !is_int($k), ARRAY_FILTER_USE_KEY));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 47) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta0sI
function name:  (null)
number of ops:  43
compiled vars:  !0 = $address, !1 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, 'Studio+5%2C+One+Infinite+Loop%2C+Cupertino+95014'
   10     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%5Cs%2A%28%5B%5E%2C%5D%2B%3F%29%5Cs%2A%28%5Cd%2B%29%24%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $3      
          6      > JMPNZ_EX                                         ~4      $3, ->12
          7    >   NEW                                              $5      'Exception'
          8        SEND_VAL_EX                                              'Failed+to+parse+city+and+zipcode+of+address'
          9        DO_FCALL                                      0          
         10      > THROW                                         1          $5
         11*       BOOL                                             ~4      <true>
   11    12    >   INIT_FCALL                                               'savecityzipcode'
         13        INIT_FCALL                                               'array_slice'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 1
         16        DO_ICALL                                         $7      
         17        SEND_UNPACK                                              $7
         18        CHECK_UNDEF_ARGS                                         
         19        DO_FCALL                                      1          
   15    20        ECHO                                                     '%0A---%0A'
   16    21        INIT_FCALL                                               'preg_match'
         22        SEND_VAL                                                 '%2F%5Cs%2A%28%3F%3Ccity%3E%5B%5E%2C%5D%2B%3F%29%5Cs%2A%28%3F%3CzipCode%3E%5Cd%2B%29%24%2F'
         23        SEND_VAR                                                 !0
         24        SEND_REF                                                 !1
         25        DO_ICALL                                         $9      
         26      > JMPNZ_EX                                         ~10     $9, ->32
         27    >   NEW                                              $11     'Exception'
         28        SEND_VAL_EX                                              'Failed+to+parse+city+and+zipcode+of+address'
         29        DO_FCALL                                      0          
         30      > THROW                                         1          $11
         31*       BOOL                                             ~10     <true>
   17    32    >   INIT_FCALL                                               'savecityzipcode'
         33        INIT_FCALL                                               'array_filter'
         34        SEND_VAR                                                 !1
         35        DECLARE_LAMBDA_FUNCTION                          ~13     [0]
         36        SEND_VAL                                                 ~13
         37        SEND_VAL                                                 2
         38        DO_ICALL                                         $14     
         39        SEND_UNPACK                                              $14
         40        CHECK_UNDEF_ARGS                                         
         41        DO_FCALL                                      1          
         42      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta0sI
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   RECV                                             !0      
          1        TYPE_CHECK                                   16  ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of Dynamic Function 0

Function savecityzipcode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta0sI
function name:  saveCityZipCode
number of ops:  7
compiled vars:  !0 = $city, !1 = $zipCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'var_dump'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                                 
    6     6      > RETURN                                                   null

End of function savecityzipcode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
199.89 ms | 1021 KiB | 19 Q