3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace { function callable_equals(){ $strict = false; $callables = func_get_args(); if(is_bool($callables[count($callables) - 1])){ $strict = $callables[count($callables) - 1]; $callables = array_splice($callables, 0, -1); } $normalizeCallable = function(callable $callable){ if(is_string($callable)){ $callable = strtolower($callable); $pieces = explode("::", $callable); if(count($pieces) == 2){ return [$pieces[0], $pieces[1]]; } return $callable; } if(is_string($callable[0])){ $callable[0] = strtolower($callable[0]); } $callable[1] = strtolower($callable[1]); return $callable; }; if(count($callables) < 2){ trigger_error("callable_equals() requires at least 2 callables for comparison.", E_USER_WARNING); return null; } foreach($callables as $i => $callable){ if(!is_callable($callable)){ trigger_error("Argument " . ($i + 1) . " is not a callable.", E_USER_WARNING); return null; }else{ $callables[$i] = $normalizeCallable($callable); } } $callable = array_shift($callables); while($callables){ if($callable !== $callables[0]) return false; } return true; } class Foo{static function bar(){}} } namespace A\b\C\d { class Foo{static function bar(){}} } namespace { var_dump(callable_equals( ['Foo', 'bar'], 'foo::BAR' )); var_dump(callable_equals( ['A\\b\\C\\d\\Foo', 'bAr'], 'a\\B\\c\\D\\FoO::bar' )); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ct7FP
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'callable_equals'
   63     2        SEND_VAL                                                 <array>
   64     3        SEND_VAL                                                 'foo%3A%3ABAR'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   67     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'callable_equals'
   68     9        SEND_VAL                                                 <array>
   69    10        SEND_VAL                                                 'a%5CB%5Cc%5CD%5CFoO%3A%3Abar'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   71    14      > RETURN                                                   1

Function callable_equals:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 52
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 52
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 46
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 58
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 62
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 52
Branch analysis from position: 18
filename:       /in/ct7FP
function name:  callable_equals
number of ops:  65
compiled vars:  !0 = $strict, !1 = $callables, !2 = $normalizeCallable, !3 = $callable, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN                                                   !0, <false>
    7     1        FUNC_GET_ARGS                                    ~6      
          2        ASSIGN                                                   !1, ~6
    9     3        COUNT                                            ~8      !1
          4        SUB                                              ~9      ~8, 1
          5        FETCH_DIM_R                                      ~10     !1, ~9
          6        TYPE_CHECK                                   12          ~10
          7      > JMPZ                                                     ~11, ->18
   10     8    >   COUNT                                            ~12     !1
          9        SUB                                              ~13     ~12, 1
         10        FETCH_DIM_R                                      ~14     !1, ~13
         11        ASSIGN                                                   !0, ~14
   11    12        INIT_FCALL                                               'array_splice'
         13        SEND_REF                                                 !1
         14        SEND_VAL                                                 0
         15        SEND_VAL                                                 -1
         16        DO_ICALL                                         $16     
         17        ASSIGN                                                   !1, $16
   14    18    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fct7FP%3A14%240'
         19        ASSIGN                                                   !2, ~18
   30    20        COUNT                                            ~20     !1
         21        IS_SMALLER                                               ~20, 2
         22      > JMPZ                                                     ~21, ->28
   31    23    >   INIT_FCALL                                               'trigger_error'
         24        SEND_VAL                                                 'callable_equals%28%29+requires+at+least+2+callables+for+comparison.'
         25        SEND_VAL                                                 512
         26        DO_ICALL                                                 
   32    27      > RETURN                                                   null
   35    28    > > FE_RESET_R                                       $23     !1, ->52
         29    > > FE_FETCH_R                                       ~24     $23, !3, ->52
         30    >   ASSIGN                                                   !4, ~24
   36    31        INIT_FCALL                                               'is_callable'
         32        SEND_VAR                                                 !3
         33        DO_ICALL                                         $26     
         34        BOOL_NOT                                         ~27     $26
         35      > JMPZ                                                     ~27, ->46
   37    36    >   INIT_FCALL                                               'trigger_error'
         37        ADD                                              ~28     !4, 1
         38        CONCAT                                           ~29     'Argument+', ~28
         39        CONCAT                                           ~30     ~29, '+is+not+a+callable.'
         40        SEND_VAL                                                 ~30
         41        SEND_VAL                                                 512
         42        DO_ICALL                                                 
   38    43        FE_FREE                                                  $23
         44      > RETURN                                                   null
         45*       JMP                                                      ->51
   40    46    >   INIT_DYNAMIC_CALL                                        !2
         47        SEND_VAR_EX                                              !3
         48        DO_FCALL                                      0  $33     
         49        ASSIGN_DIM                                               !1, !4
         50        OP_DATA                                                  $33
   35    51      > JMP                                                      ->29
         52    >   FE_FREE                                                  $23
   44    53        INIT_FCALL                                               'array_shift'
         54        SEND_REF                                                 !1
         55        DO_ICALL                                         $34     
         56        ASSIGN                                                   !3, $34
   45    57      > JMP                                                      ->62
   46    58    >   FETCH_DIM_R                                      ~36     !1, 0
         59        IS_NOT_IDENTICAL                                         !3, ~36
         60      > JMPZ                                                     ~37, ->62
   47    61    > > RETURN                                                   <false>
   45    62    > > JMPNZ                                                    !1, ->58
   49    63    > > RETURN                                                   <true>
   50    64*     > RETURN                                                   null

End of function callable_equals

Function %00%7Bclosure%7D%2Fin%2Fct7FP%3A14%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/ct7FP
function name:  {closure}
number of ops:  38
compiled vars:  !0 = $callable, !1 = $pieces
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~2, ->21
   16     3    >   INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !0, $3
   17     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%3A%3A'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $5      
         11        ASSIGN                                                   !1, $5
   18    12        COUNT                                            ~7      !1
         13        IS_EQUAL                                                 ~7, 2
         14      > JMPZ                                                     ~8, ->20
   19    15    >   FETCH_DIM_R                                      ~9      !1, 0
         16        INIT_ARRAY                                       ~10     ~9
         17        FETCH_DIM_R                                      ~11     !1, 1
         18        ADD_ARRAY_ELEMENT                                ~10     ~11
         19      > RETURN                                                   ~10
   21    20    > > RETURN                                                   !0
   23    21    >   FETCH_DIM_R                                      ~12     !0, 0
         22        TYPE_CHECK                                   64          ~12
         23      > JMPZ                                                     ~13, ->30
   24    24    >   INIT_FCALL                                               'strtolower'
         25        FETCH_DIM_R                                      ~15     !0, 0
         26        SEND_VAL                                                 ~15
         27        DO_ICALL                                         $16     
         28        ASSIGN_DIM                                               !0, 0
         29        OP_DATA                                                  $16
   26    30    >   INIT_FCALL                                               'strtolower'
         31        FETCH_DIM_R                                      ~18     !0, 1
         32        SEND_VAL                                                 ~18
         33        DO_ICALL                                         $19     
         34        ASSIGN_DIM                                               !0, 1
         35        OP_DATA                                                  $19
   27    36      > RETURN                                                   !0
   28    37*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fct7FP%3A14%240

Class Foo:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ct7FP
function name:  bar
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E > > RETURN                                                   null

End of function bar

End of class Foo.

Class A\b\C\d\Foo:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ct7FP
function name:  bar
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E > > RETURN                                                   null

End of function bar

End of class A\b\C\d\Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.91 ms | 1402 KiB | 29 Q