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 exceptionQuestion extends Exception { public function getAnswer($that) { $answerClosure = Closure::bind(function () { return $this->answer; }, $that, $that); $answer = $answerClosure($that); return $answer; } } $e = new exceptionQuestion(); // end editing here new Question($e);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ug4Jt
function name:  (null)
number of ops:  8
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $1      'exceptionQuestion'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   50     3        NEW                                              $4      'Question'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        FREE                                                     $4
          7      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fug4Jt%3A32%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ug4Jt
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_THIS                                       $0      
          1        FETCH_OBJ_R                                      ~1      $0, 'answer'
          2      > RETURN                                                   ~1
   34     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fug4Jt%3A32%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/ug4Jt
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 exceptionQuestion:
Function getanswer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ug4Jt
function name:  getAnswer
number of ops:  14
compiled vars:  !0 = $that, !1 = $answerClosure, !2 = $answer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   32     1        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fug4Jt%3A32%240'
   34     3        SEND_VAL                                                 ~3
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
   32     7        ASSIGN                                                   !1, $4
   36     8        INIT_DYNAMIC_CALL                                        !1
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $6      
         11        ASSIGN                                                   !2, $6
   38    12      > RETURN                                                   !2
   39    13*     > RETURN                                                   null

End of function getanswer

End of class exceptionQuestion.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.46 ms | 1399 KiB | 13 Q