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->answer; }, $that, $that); var_dump($answerTime); var_dump($sweetsThief($that)); } 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/eU5tS
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                                                      
  61     3        NEW                                              $4      :-4
         4        DO_FCALL                                      0          
         5        ASSIGN                                                   !0, $4
  65     6        NEW                                                      :-2
         7        SEND_VAR_EX                                              !0
         8        DO_FCALL                                      0          
         9      > RETURN                                                   1

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

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

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/eU5tS
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/eU5tS
function name:  getAnswer
number of ops:  18
compiled vars:  !0 = $that, !1 = $answerTime, !2 = $sweetsThief
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%2FeU5tS0x7fa23ec332bb'
         3        SEND_VAL_EX                                              ~3
         4        SEND_VAR_EX                                              !0
         5        SEND_VAR_EX                                              !0
         6        DO_FCALL                                      0  $4      
         7        ASSIGN                                                   !1, $4
  46     8        INIT_FCALL                                               'var_dump'
         9        SEND_VAR                                                 !1
        10        DO_ICALL                                                 
  47    11        INIT_FCALL                                               'var_dump'
        12        INIT_DYNAMIC_CALL                                        !2
        13        SEND_VAR_EX                                              !0
        14        DO_FCALL                                      0  $7      
        15        SEND_VAR                                                 $7
        16        DO_ICALL                                                 
  48    17      > RETURN                                                   null

End of function getanswer

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

End of function getprivate

End of class exceptionFun.

Generated using Vulcan Logic Dumper, using php 7.2.0