3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getHookPattern($hook) { return preg_replace( '/^(?<prefix>[a-z0-9_]+_)?[A-Z][A-Z0-9_]+(?<suffix>_[a-z0-9]+)?$/', '${1}[a-z0-9_]+${2}', $hook ); } $hooks = [ 'form_alter', 'form_FORM_ID_alter', 'entity_query_tag__ENTITY_TYPE__TAG_alter', 'ENTITY_TYPE_insert', 'preprocess_BLOCK', 'foo_BAR0_baz', 'foo_BAR_0baz', 'foo_BAR_0_baz', ]; foreach ($hooks as $hook) { print getHookPattern($hook) . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/jR9IT
function name:  (null)
number of ops:  11
compiled vars:  !0 = $hooks, !1 = $hook
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   23     1      > FE_RESET_R                                       $3      !0, ->9
          2    > > FE_FETCH_R                                               $3, !1, ->9
   24     3    >   INIT_FCALL                                               'gethookpattern'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   23     8      > JMP                                                      ->2
          9    >   FE_FREE                                                  $3
   25    10      > RETURN                                                   1

Function gethookpattern:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jR9IT
function name:  getHookPattern
number of ops:  8
compiled vars:  !0 = $hook
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_replace'
    5     2        SEND_VAL                                                 '%2F%5E%28%3F%3Cprefix%3E%5Ba-z0-9_%5D%2B_%29%3F%5BA-Z%5D%5BA-Z0-9_%5D%2B%28%3F%3Csuffix%3E_%5Ba-z0-9%5D%2B%29%3F%24%2F'
    6     3        SEND_VAL                                                 '%24%7B1%7D%5Ba-z0-9_%5D%2B%24%7B2%7D'
    7     4        SEND_VAR                                                 !0
    4     5        DO_ICALL                                         $1      
    7     6      > RETURN                                                   $1
    9     7*     > RETURN                                                   null

End of function gethookpattern

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.6 ms | 1012 KiB | 15 Q