3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Challenge 3: Use reflection to get access to Question::$answer from $e->getAnswer */ class Question { private $answer = 42; public function __construct($e) { try { throw $e; } catch (Exception $e) { echo $e->getAnswer($this) . PHP_EOL; } } } // start editing here class exceptionFun extends Exception { public $that; public function getAnswer($that) { /* $this->that = $that; $answerTime = Closure::bind($this->getPrivate(), null, $that); var_dump($answerTime); */ $func = function() use ($that) { $that->answer; // Can see protected method //$test::findMeStatically(); // Can see static protected method }; $func(); var_dump($func); //return $func; } public function getPrivate() { $that = $this->that; return $that->answer; } } $e = new exceptionFun(); // end editing here new Question($e);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ETouo
function name:  (null)
number of ops:  8
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   NEW                                              $1      'exceptionFun'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   67     3        NEW                                              $4      'Question'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        FREE                                                     $4
          7      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FETouo%3A42%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ETouo
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $that
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   BIND_STATIC                                              !0
   43     1        FETCH_OBJ_R                                      ~1      !0, 'answer'
          2        FREE                                                     ~1
   45     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FETouo%3A42%240

Class Question:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 108) Position 1 = -2
Found catch point at position: 3
Branch analysis from position: 3
2 jumps found. (Code = 107) Position 1 = 4, Position 2 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ETouo
function name:  __construct
number of ops:  11
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   14     1      > THROW                                         0          !0
          2*       JMP                                                      ->10
   15     3  E > > CATCH                                       last         'Exception'
   16     4    >   INIT_METHOD_CALL                                         !0, 'getAnswer'
          5        FETCH_THIS                                       $1      
          6        SEND_VAR_EX                                              $1
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
   18    10      > RETURN                                                   null

End of function __construct

End of class Question.

Class exceptionFun:
Function getanswer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ETouo
function name:  getAnswer
number of ops:  10
compiled vars:  !0 = $that, !1 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   42     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FETouo%3A42%240'
          2        BIND_LEXICAL                                             ~2, !0
          3        ASSIGN                                                   !1, ~2
   46     4        INIT_DYNAMIC_CALL                                        !1
          5        DO_FCALL                                      0          
   47     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   50     9      > RETURN                                                   null

End of function getanswer

Function getprivate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ETouo
function name:  getPrivate
number of ops:  5
compiled vars:  !0 = $that
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   FETCH_OBJ_R                                      ~1      'that'
          1        ASSIGN                                                   !0, ~1
   55     2        FETCH_OBJ_R                                      ~3      !0, 'answer'
          3      > RETURN                                                   ~3
   56     4*     > RETURN                                                   null

End of function getprivate

End of class exceptionFun.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.55 ms | 1404 KiB | 15 Q