3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected string $property; public function __construct(string $property) { $this->property = $property; } public function getProperty(): string { return $this->property; } } $foo = new Foo("foo"); echo "Default value:\n"; var_dump($foo->getProperty()); echo "\nInvoking the __constructor() method again:\n"; $foo->__construct("baz"); var_dump($foo->getProperty()); // https://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/ echo "\nClosure binding:\n"; Closure::bind( function (): void { $this->property = "bang"; }, $foo, $foo )->__invoke(); var_dump($foo->getProperty()); echo "\nAbusing anonymous classes:\n"; $fooAbuser = new class("") extends Foo { public function abuse(Foo $foo): Foo { $foo->property = "boom"; return $foo; } }; var_dump($fooAbuser->abuse($foo)->getProperty());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta4PM
function name:  (null)
number of ops:  48
compiled vars:  !0 = $foo, !1 = $fooAbuser
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $2      'Foo'
          1        SEND_VAL_EX                                              'foo'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   19     4        ECHO                                                     'Default+value%3A%0A'
   20     5        INIT_FCALL                                               'var_dump'
          6        INIT_METHOD_CALL                                         !0, 'getProperty'
          7        DO_FCALL                                      0  $5      
          8        SEND_VAR                                                 $5
          9        DO_ICALL                                                 
   22    10        ECHO                                                     '%0AInvoking+the+__constructor%28%29+method+again%3A%0A'
   23    11        INIT_METHOD_CALL                                         !0, '__construct'
         12        SEND_VAL_EX                                              'baz'
         13        DO_FCALL                                      0          
   24    14        INIT_FCALL                                               'var_dump'
         15        INIT_METHOD_CALL                                         !0, 'getProperty'
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR                                                 $8
         18        DO_ICALL                                                 
   27    19        ECHO                                                     '%0AClosure+binding%3A%0A'
   28    20        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
   29    21        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTa4PM%3A29%240'
   31    22        SEND_VAL                                                 ~10
   32    23        SEND_VAR                                                 !0
   33    24        SEND_VAR                                                 !0
         25        DO_FCALL                                      0  $11     
   34    26        INIT_METHOD_CALL                                         $11, '__invoke'
         27        DO_FCALL                                      0          
   35    28        INIT_FCALL                                               'var_dump'
         29        INIT_METHOD_CALL                                         !0, 'getProperty'
         30        DO_FCALL                                      0  $13     
         31        SEND_VAR                                                 $13
         32        DO_ICALL                                                 
   37    33        ECHO                                                     '%0AAbusing+anonymous+classes%3A%0A'
   38    34        DECLARE_ANON_CLASS                               <undef> 'foo'
         35        NEW                                              $16     $15
         36        SEND_VAL_EX                                              ''
         37        DO_FCALL                                      0          
         38        ASSIGN                                                   !1, $16
   48    39        INIT_FCALL                                               'var_dump'
         40        INIT_METHOD_CALL                                         !1, 'abuse'
         41        SEND_VAR_EX                                              !0
         42        DO_FCALL                                      0  $19     
         43        INIT_METHOD_CALL                                         $19, 'getProperty'
         44        DO_FCALL                                      0  $20     
         45        SEND_VAR                                                 $20
         46        DO_ICALL                                                 
         47      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FTa4PM%3A29%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta4PM
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_THIS                                       $0      
          1        ASSIGN_OBJ                                               $0, 'property'
          2        OP_DATA                                                  'bang'
   31     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTa4PM%3A29%240

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta4PM
function name:  __construct
number of ops:  4
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        ASSIGN_OBJ                                               'property'
          2        OP_DATA                                                  !0
    9     3      > RETURN                                                   null

End of function __construct

Function getproperty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta4PM
function name:  getProperty
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_OBJ_R                                      ~0      'property'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   14     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getproperty

End of class Foo.

Class Foo@anonymous:
Function abuse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ta4PM
function name:  abuse
number of ops:  7
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        ASSIGN_OBJ                                               !0, 'property'
          2        OP_DATA                                                  'boom'
   44     3        VERIFY_RETURN_TYPE                                       !0
          4      > RETURN                                                   !0
   45     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function abuse

End of class Foo@anonymous.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.96 ms | 1400 KiB | 15 Q