3v4l.org

run code in 300+ PHP versions simultaneously
<?php function guessObjectMethod($object, string $fieldName, string $prefix): ?string { if (\is_callable([$object, $method = $prefix.\str_replace(' ', '', \ucwords(\str_replace('_', ' ', $fieldName)))])) { return $method; } return null; } class Data { public function isValid() : bool { return true; } } $data = new Data(); var_dump(guessObjectMethod($data, 'valid', 'get')); var_dump(guessObjectMethod($data, 'isValid', 'get')); var_dump(guessObjectMethod($data, 'valid', 'is')); var_dump(guessObjectMethod($data, 'isValid', 'is')); // if my property is called `isValid` it won't work!
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tfb8l
function name:  (null)
number of ops:  36
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $1      'Data'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   20     3        INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'guessobjectmethod'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'valid'
          7        SEND_VAL                                                 'get'
          8        DO_FCALL                                      0  $4      
          9        SEND_VAR                                                 $4
         10        DO_ICALL                                                 
   21    11        INIT_FCALL                                               'var_dump'
         12        INIT_FCALL                                               'guessobjectmethod'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 'isValid'
         15        SEND_VAL                                                 'get'
         16        DO_FCALL                                      0  $6      
         17        SEND_VAR                                                 $6
         18        DO_ICALL                                                 
   22    19        INIT_FCALL                                               'var_dump'
         20        INIT_FCALL                                               'guessobjectmethod'
         21        SEND_VAR                                                 !0
         22        SEND_VAL                                                 'valid'
         23        SEND_VAL                                                 'is'
         24        DO_FCALL                                      0  $8      
         25        SEND_VAR                                                 $8
         26        DO_ICALL                                                 
   23    27        INIT_FCALL                                               'var_dump'
         28        INIT_FCALL                                               'guessobjectmethod'
         29        SEND_VAR                                                 !0
         30        SEND_VAL                                                 'isValid'
         31        SEND_VAL                                                 'is'
         32        DO_FCALL                                      0  $10     
         33        SEND_VAR                                                 $10
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Function guessobjectmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tfb8l
function name:  guessObjectMethod
number of ops:  29
compiled vars:  !0 = $object, !1 = $fieldName, !2 = $prefix, !3 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        INIT_FCALL                                               'is_callable'
          4        INIT_ARRAY                                       ~4      !0
          5        INIT_FCALL                                               'str_replace'
          6        SEND_VAL                                                 '+'
          7        SEND_VAL                                                 ''
          8        INIT_FCALL                                               'ucwords'
          9        INIT_FCALL                                               'str_replace'
         10        SEND_VAL                                                 '_'
         11        SEND_VAL                                                 '+'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $5      
         14        SEND_VAR                                                 $5
         15        DO_ICALL                                         $6      
         16        SEND_VAR                                                 $6
         17        DO_ICALL                                         $7      
         18        CONCAT                                           ~8      !2, $7
         19        ASSIGN                                           ~9      !3, ~8
         20        ADD_ARRAY_ELEMENT                                ~4      ~9
         21        SEND_VAL                                                 ~4
         22        DO_ICALL                                         $10     
         23      > JMPZ                                                     $10, ->26
    6    24    >   VERIFY_RETURN_TYPE                                       !3
         25      > RETURN                                                   !3
    9    26    > > RETURN                                                   null
   10    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function guessobjectmethod

Class Data:
Function isvalid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tfb8l
function name:  isValid
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E > > RETURN                                                   <true>
   16     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function isvalid

End of class Data.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.92 ms | 1008 KiB | 21 Q