3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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; $callable = array_shift($callables); } 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' )); }
based on ct7FP
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C5sEe
function name:  (null)
number of ops:  18
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   4     0  E >   NOP                                                      
  53     1        NOP                                                      
  58     2        NOP                                                      
  63     3        INIT_FCALL                                               'var_dump'
         4        INIT_FCALL                                               'callable_equals'
  64     5        SEND_VAL                                                 <array>
  65     6        SEND_VAL                                                 'foo%3A%3ABAR'
         7        DO_FCALL                                      0  $2      
         8        SEND_VAR                                                 $2
         9        DO_ICALL                                                 
  68    10        INIT_FCALL                                               'var_dump'
        11        INIT_FCALL                                               'callable_equals'
  69    12        SEND_VAL                                                 <array>
  70    13        SEND_VAL                                                 'a%5CB%5Cc%5CD%5CFoO%3A%3Abar'
        14        DO_FCALL                                      0  $4      
        15        SEND_VAR                                                 $4
        16        DO_ICALL                                                 
  72    17      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FC5sEe0x7ff94c83535c:
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/C5sEe
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                                    6  ~2      !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                                         ~8      ~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                                    6  ~13     $12
        23      > JMPZ                                                     ~13, ->30
  24    24    >   INIT_FCALL                                               'strtolower'
        25        FETCH_DIM_R                                      $15     !0, 0
        26        SEND_VAR                                                 $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_VAR                                                 $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%2FC5sEe0x7ff94c83535c

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 = 66
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 58
Branch analysis from position: 67
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
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 58
Branch analysis from position: 67
Branch analysis from position: 58
Branch analysis from position: 52
Branch analysis from position: 18
filename:       /in/C5sEe
function name:  callable_equals
number of ops:  69
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                                   13  ~11     $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%2FC5sEe0x7ff94c83535c'
  28    19        ASSIGN                                                   !2, ~18
  30    20        COUNT                                            ~20     !1
        21        IS_SMALLER                                       ~21     ~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
        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                                                      ->66
  46    58    >   FETCH_DIM_R                                      $36     !1, 0
        59        IS_NOT_IDENTICAL                                 ~37     !3, $36
        60      > JMPZ                                                     ~37, ->62
  47    61    > > RETURN                                                   <false>
  48    62    >   INIT_FCALL                                               'array_shift'
        63        SEND_REF                                                 !1
        64        DO_ICALL                                         $38     
        65        ASSIGN                                                   !3, $38
  45    66    > > JMPNZ                                                    !1, ->58
  50    67    > > RETURN                                                   <true>
  51    68*     > RETURN                                                   null

End of function callable_equals

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

End of function bar

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

Generated using Vulcan Logic Dumper, using php 7.3.0