3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Reduced core class from MediaWiki to demonstrate an issue starting with 7.1.0alpha2 // https://github.com/wikimedia/mediawiki/blob/master/includes/Hooks.php class Hooks { protected static $handlers = array(); public static function register( $name, $callback ) { if ( !isset( self::$handlers[$name] ) ) { self::$handlers[$name] = array(); } self::$handlers[$name][] = $callback; } public static function run( $event, array $args = array() ) { foreach ( self::$handlers[$event] as $hook ) { if ( !is_array( $hook ) ) { $hook = array( $hook ); } if ( !array_filter( $hook ) ) { continue; } elseif ( is_array( $hook[0] ) ) { $hook = array_merge( $hook[0], array_slice( $hook, 1 ) ); } if ( $hook[0] instanceof Closure ) { $func = "hook-$event-closure"; $callback = array_shift( $hook ); } elseif ( is_object( $hook[0] ) ) { $object = array_shift( $hook ); $method = array_shift( $hook ); if ( $method === null ) { $method = "on$event"; } $func = get_class( $object ) . '::' . $method; $callback = array( $object, $method ); } elseif ( is_string( $hook[0] ) ) { $func = $callback = array_shift( $hook ); } $retval = null; $badhookmsg = null; $hook_args = array_merge( $hook, $args ); $retval = call_user_func_array( $callback, $args ); } } } Hooks::register( 'foo', function( &$foo, &$var ) { $var = $var . '-bar'; } ); //Stub class using &$this as direct reference class Foo { public function doSomething( $var ) { Hooks::run( 'foo', array( &$this, &$var ) ); return $var; } } // Stub class causes no error after $this is being redeclared class Foo2 { public function doSomething( $var ) { $foo = $this; Hooks::run( 'foo', array( &$foo, &$var ) ); return $var; } } // Causes an error $fooA = new Foo(); $varA = $fooA->doSomething( '123' ); echo "Foo: \n"; echo $varA . "\n"; // Causes no error $fooB = new Foo2(); $varB = $fooB->doSomething( '123' ); echo "Foo2: \n"; echo $varB;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vMc1N
function name:  (null)
number of ops:  25
compiled vars:  !0 = $fooA, !1 = $varA, !2 = $fooB, !3 = $varB
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_STATIC_METHOD_CALL                                  'Hooks', 'register'
          1        SEND_VAL                                                 'foo'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FvMc1N%3A56%240'
   58     3        SEND_VAL                                                 ~4
          4        DO_FCALL                                      0          
   83     5        NEW                                              $6      'Foo'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $6
   84     8        INIT_METHOD_CALL                                         !0, 'doSomething'
          9        SEND_VAL_EX                                              '123'
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !1, $9
   86    12        ECHO                                                     'Foo%3A+%0A'
   87    13        CONCAT                                           ~11     !1, '%0A'
         14        ECHO                                                     ~11
   90    15        NEW                                              $12     'Foo2'
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !2, $12
   91    18        INIT_METHOD_CALL                                         !2, 'doSomething'
         19        SEND_VAL_EX                                              '123'
         20        DO_FCALL                                      0  $15     
         21        ASSIGN                                                   !3, $15
   93    22        ECHO                                                     'Foo2%3A+%0A'
   94    23        ECHO                                                     !3
         24      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FvMc1N%3A56%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vMc1N
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $foo, !1 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   57     2        CONCAT                                           ~2      !1, '-bar'
          3        ASSIGN                                                   !1, ~2
   58     4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FvMc1N%3A56%240

Class Hooks:
Function register:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/vMc1N
function name:  register
number of ops:  14
compiled vars:  !0 = $name, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        FETCH_STATIC_PROP_IS                             ~2      'handlers'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~2, !0
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->9
   11     6    >   FETCH_STATIC_PROP_W          unknown             $5      'handlers'
          7        ASSIGN_DIM                                               $5, !0
          8        OP_DATA                                                  <array>
   14     9    >   FETCH_STATIC_PROP_W          unknown             $7      'handlers'
         10        FETCH_DIM_W                                      $8      $7, !0
         11        ASSIGN_DIM                                               $8
         12        OP_DATA                                                  !1
   15    13      > RETURN                                                   null

End of function register

Function run:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 88
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 88
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 31
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 43
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 67
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
Branch analysis from position: 59
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 75
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 75
Branch analysis from position: 31
Branch analysis from position: 11
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 88
filename:       /in/vMc1N
function name:  run
number of ops:  90
compiled vars:  !0 = $event, !1 = $args, !2 = $hook, !3 = $func, !4 = $callback, !5 = $object, !6 = $method, !7 = $retval, !8 = $badhookmsg, !9 = $hook_args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   18     2        FETCH_STATIC_PROP_R          unknown             ~10     'handlers'
          3        FETCH_DIM_R                                      ~11     ~10, !0
          4      > FE_RESET_R                                       $12     ~11, ->88
          5    > > FE_FETCH_R                                               $12, !2, ->88
   20     6    >   TYPE_CHECK                                  128  ~13     !2
          7        BOOL_NOT                                         ~14     ~13
          8      > JMPZ                                                     ~14, ->11
   21     9    >   INIT_ARRAY                                       ~15     !2
         10        ASSIGN                                                   !2, ~15
   24    11    >   INIT_FCALL                                               'array_filter'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $17     
         14        BOOL_NOT                                         ~18     $17
         15      > JMPZ                                                     ~18, ->18
   25    16    > > JMP                                                      ->5
         17*       JMP                                                      ->31
   26    18    >   FETCH_DIM_R                                      ~19     !2, 0
         19        TYPE_CHECK                                  128          ~19
         20      > JMPZ                                                     ~20, ->31
   27    21    >   INIT_FCALL                                               'array_merge'
         22        FETCH_DIM_R                                      ~21     !2, 0
         23        SEND_VAL                                                 ~21
         24        INIT_FCALL                                               'array_slice'
         25        SEND_VAR                                                 !2
         26        SEND_VAL                                                 1
         27        DO_ICALL                                         $22     
         28        SEND_VAR                                                 $22
         29        DO_ICALL                                         $23     
         30        ASSIGN                                                   !2, $23
   30    31    >   FETCH_DIM_R                                      ~25     !2, 0
         32        INSTANCEOF                                               ~25, 'Closure'
         33      > JMPZ                                                     ~26, ->43
   31    34    >   ROPE_INIT                                     3  ~28     'hook-'
         35        ROPE_ADD                                      1  ~28     ~28, !0
         36        ROPE_END                                      2  ~27     ~28, '-closure'
         37        ASSIGN                                                   !3, ~27
   32    38        INIT_FCALL                                               'array_shift'
         39        SEND_REF                                                 !2
         40        DO_ICALL                                         $31     
         41        ASSIGN                                                   !4, $31
         42      > JMP                                                      ->75
   33    43    >   FETCH_DIM_R                                      ~33     !2, 0
         44        TYPE_CHECK                                  256          ~33
         45      > JMPZ                                                     ~34, ->67
   34    46    >   INIT_FCALL                                               'array_shift'
         47        SEND_REF                                                 !2
         48        DO_ICALL                                         $35     
         49        ASSIGN                                                   !5, $35
   35    50        INIT_FCALL                                               'array_shift'
         51        SEND_REF                                                 !2
         52        DO_ICALL                                         $37     
         53        ASSIGN                                                   !6, $37
   37    54        TYPE_CHECK                                    2          !6
         55      > JMPZ                                                     ~39, ->59
   38    56    >   NOP                                                      
         57        FAST_CONCAT                                      ~40     'on', !0
         58        ASSIGN                                                   !6, ~40
   41    59    >   GET_CLASS                                        ~42     !5
         60        CONCAT                                           ~43     ~42, '%3A%3A'
         61        CONCAT                                           ~44     ~43, !6
         62        ASSIGN                                                   !3, ~44
   42    63        INIT_ARRAY                                       ~46     !5
         64        ADD_ARRAY_ELEMENT                                ~46     !6
         65        ASSIGN                                                   !4, ~46
         66      > JMP                                                      ->75
   43    67    >   FETCH_DIM_R                                      ~48     !2, 0
         68        TYPE_CHECK                                   64          ~48
         69      > JMPZ                                                     ~49, ->75
   44    70    >   INIT_FCALL                                               'array_shift'
         71        SEND_REF                                                 !2
         72        DO_ICALL                                         $50     
         73        ASSIGN                                           ~51     !4, $50
         74        ASSIGN                                                   !3, ~51
   47    75    >   ASSIGN                                                   !7, null
   48    76        ASSIGN                                                   !8, null
   49    77        INIT_FCALL                                               'array_merge'
         78        SEND_VAR                                                 !2
         79        SEND_VAR                                                 !1
         80        DO_ICALL                                         $55     
         81        ASSIGN                                                   !9, $55
   51    82        INIT_USER_CALL                                0          'call_user_func_array', !4
         83        SEND_ARRAY                                               !1
         84        CHECK_UNDEF_ARGS                                         
         85        DO_FCALL                                      0  $57     
         86        ASSIGN                                                   !7, $57
   18    87      > JMP                                                      ->5
         88    >   FE_FREE                                                  $12
   53    89      > RETURN                                                   null

End of function run

End of class Hooks.

Class Foo:
Function dosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vMc1N
function name:  doSomething
number of ops:  10
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
   64     1        INIT_STATIC_METHOD_CALL                                  'Hooks', 'run'
          2        SEND_VAL                                                 'foo'
          3        FETCH_THIS                                       $1      
          4        INIT_ARRAY                                       ~2      $1
          5        ADD_ARRAY_ELEMENT                                ~2      !0
          6        SEND_VAL                                                 ~2
          7        DO_FCALL                                      0          
   65     8      > RETURN                                                   !0
   66     9*     > RETURN                                                   null

End of function dosomething

End of class Foo.

Class Foo2:
Function dosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vMc1N
function name:  doSomething
number of ops:  11
compiled vars:  !0 = $var, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   74     1        FETCH_THIS                                       ~2      
          2        ASSIGN                                                   !1, ~2
   76     3        INIT_STATIC_METHOD_CALL                                  'Hooks', 'run'
          4        SEND_VAL                                                 'foo'
          5        INIT_ARRAY                                       ~4      !1
          6        ADD_ARRAY_ELEMENT                                ~4      !0
          7        SEND_VAL                                                 ~4
          8        DO_FCALL                                      0          
   77     9      > RETURN                                                   !0
   78    10*     > RETURN                                                   null

End of function dosomething

End of class Foo2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
130.38 ms | 1417 KiB | 21 Q