3v4l.org

run code in 300+ PHP versions simultaneously
<?php function camelize($id) { return preg_replace(array('/(^|_|-)+(.)/e', '/\.(.)/e'), array("strtoupper('\\2')", "'_'.strtoupper('\\1')"), $id); } function camelize2($id) { return preg_replace_callback_array([ '/(^|_|-)+(.)/e' => function ($match) { return strtoupper($match[2]); }, '/\.(.)/e' => function ($match) { return '_' . strtoupper($match[1]); } ], $id); } $text = "_salut_les-amis!!"; var_dump(camelize($text), camelize2($text));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PRXoE
function name:  (null)
number of ops:  12
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, '_salut_les-amis%21%21'
   22     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'camelize'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        INIT_FCALL                                               'camelize2'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function camelize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PRXoE
function name:  camelize
number of ops:  8
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 <array>
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
    6     7*     > RETURN                                                   null

End of function camelize

Function camelize2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PRXoE
function name:  camelize2
number of ops:  11
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'preg_replace_callback_array'
   11     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FPRXoE%3A11%240'
   13     3        INIT_ARRAY                                       ~2      ~1, '%2F%28%5E%7C_%7C-%29%2B%28.%29%2Fe'
   14     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FPRXoE%3A14%241'
   16     5        ADD_ARRAY_ELEMENT                                ~2      ~3, '%2F%5C.%28.%29%2Fe'
          6        SEND_VAL                                                 ~2
   17     7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $4      
          9      > RETURN                                                   $4
   18    10*     > RETURN                                                   null

End of function camelize2

Function %00%7Bclosure%7D%2Fin%2FPRXoE%3A11%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PRXoE
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'strtoupper'
          2        FETCH_DIM_R                                      ~1      !0, 2
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5      > RETURN                                                   $2
   13     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FPRXoE%3A11%240

Function %00%7Bclosure%7D%2Fin%2FPRXoE%3A14%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PRXoE
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'strtoupper'
          2        FETCH_DIM_R                                      ~1      !0, 1
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5        CONCAT                                           ~3      '_', $2
          6      > RETURN                                                   ~3
   16     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FPRXoE%3A14%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
300.19 ms | 1403 KiB | 24 Q