3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo preg_replace_callback('/([a-z])(_[a-z])/', function($u) { //var_dump($u); return $u[1].ucwords(str_replace('_', '', $u[2])); } , 'rob_tr_yuui'); echo PHP_EOL; echo preg_replace('/([a-z])(_[a-z])/', '$1$2', 'rob_tr_yuui'); function to_camel_case($str, $capitalise_first_char = false) { if($capitalise_first_char) { $str[0] = strtoupper($str[0]); } $func = create_function('$c', 'return strtoupper($c[1]);'); return preg_replace_callback('/_([a-z])/', $func, $str); } echo PHP_EOL; echo to_camel_case('rob_tr_yuui');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QduQl
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   INIT_FCALL                                               'preg_replace_callback'
          1        SEND_VAL                                                 '%2F%28%5Ba-z%5D%29%28_%5Ba-z%5D%29%2F'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQduQl%3A6%240'
   14     3        SEND_VAL                                                 ~0
   15     4        SEND_VAL                                                 'rob_tr_yuui'
          5        DO_ICALL                                         $1      
          6        ECHO                                                     $1
   20     7        ECHO                                                     '%0A'
   26     8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAL                                                 '%2F%28%5Ba-z%5D%29%28_%5Ba-z%5D%29%2F'
         10        SEND_VAL                                                 '%241%242'
         11        SEND_VAL                                                 'rob_tr_yuui'
         12        DO_ICALL                                         $2      
         13        ECHO                                                     $2
   46    14        ECHO                                                     '%0A'
   49    15        INIT_FCALL                                               'to_camel_case'
         16        SEND_VAL                                                 'rob_tr_yuui'
         17        DO_FCALL                                      0  $3      
         18        ECHO                                                     $3
         19      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FQduQl%3A6%240

Function to_camel_case:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/QduQl
function name:  to_camel_case
number of ops:  21
compiled vars:  !0 = $str, !1 = $capitalise_first_char, !2 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   34     2      > JMPZ                                                     !1, ->9
   35     3    >   INIT_FCALL                                               'strtoupper'
          4        FETCH_DIM_R                                      ~4      !0, 0
          5        SEND_VAL                                                 ~4
          6        DO_ICALL                                         $5      
          7        ASSIGN_DIM                                               !0, 0
          8        OP_DATA                                                  $5
   37     9    >   INIT_FCALL_BY_NAME                                       'create_function'
         10        SEND_VAL_EX                                              '%24c'
         11        SEND_VAL_EX                                              'return+strtoupper%28%24c%5B1%5D%29%3B'
         12        DO_FCALL                                      0  $6      
         13        ASSIGN                                                   !2, $6
   38    14        INIT_FCALL                                               'preg_replace_callback'
         15        SEND_VAL                                                 '%2F_%28%5Ba-z%5D%29%2F'
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $8      
         19      > RETURN                                                   $8
   39    20*     > RETURN                                                   null

End of function to_camel_case

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.89 ms | 1403 KiB | 24 Q