3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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); */ //$this->that = $that; $answerTime = Closure::bind(function () { return $this->$this->answer; }, $that, $that); var_dump($answerTime); } 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
Jump found. Position 1 = -2
filename:       /in/IdsIW
function name:  (null)
number of ops:  10
compiled vars:  !0 = $e
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   NOP                                                      
  26     1        NOP                                                      
         2        NOP                                                      
  60     3        NEW                                              $4      :-4
         4        DO_FCALL                                      0          
         5        ASSIGN                                                   !0, $4
  64     6        NEW                                                      :-2
         7        SEND_VAR_EX                                              !0
         8        DO_FCALL                                      0          
         9      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FIdsIW0x7f5ed1b562c2:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/IdsIW
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  43     0  E >   FETCH_OBJ_R                                      $1      !0
         1        FETCH_OBJ_R                                      $2      $1, 'answer'
         2      > RETURN                                                   $2
         3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIdsIW0x7f5ed1b562c2

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

End of function __construct

End of class Question.

Class exceptionFun:
Function getanswer:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/IdsIW
function name:  getAnswer
number of ops:  12
compiled vars:  !0 = $that, !1 = $answerTime
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  31     0  E >   RECV                                             !0      
  43     1        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIdsIW0x7f5ed1b562c2'
         3        SEND_VAL_EX                                              ~2
         4        SEND_VAR_EX                                              !0
         5        SEND_VAR_EX                                              !0
         6        DO_FCALL                                      0  $3      
         7        ASSIGN                                                   !1, $3
  46     8        INIT_FCALL                                               'var_dump'
         9        SEND_VAR                                                 !1
        10        DO_ICALL                                                 
  47    11      > RETURN                                                   null

End of function getanswer

Function getprivate:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/IdsIW
function name:  getPrivate
number of ops:  5
compiled vars:  !0 = $that
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  51     0  E >   FETCH_OBJ_R                                      $1      'that'
         1        ASSIGN                                                   !0, $1
  52     2        FETCH_OBJ_R                                      $3      !0, 'answer'
         3      > RETURN                                                   $3
  53     4*     > RETURN                                                   null

End of function getprivate

End of class exceptionFun.

Generated using Vulcan Logic Dumper, using php 7.3.0