3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Challenge 2: Implement AnswerInterface and get Question to echo "4". */ class Question { public function __construct(AnswerInterface $answer) { echo "What is 2 + 2?\n"; $anaaswer = $answer->get()->the()->_answer(); if ($answer instanceof AnswerInterface) { echo $anaaswer . PHP_EOL; } } } interface AnswerInterface { public function get(); public function the(); public function _answer(); } // start editing here class Answer implements AnswerInterface { public function get() { return $this; } public function the() { return $this; } public function _answer() { return 4; } } // end editing here $answer = new Answer; $question = new Question($answer);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/drHBY
function name:  (null)
number of ops:  9
compiled vars:  !0 = $answer, !1 = $question
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   DECLARE_CLASS                                            'answer'
   43     1        NEW                                              $2      'Answer'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   44     4        NEW                                              $5      'Question'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
          8      > RETURN                                                   1

Class Question:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/drHBY
function name:  __construct
number of ops:  14
compiled vars:  !0 = $answer, !1 = $anaaswer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        ECHO                                                     'What+is+2+%2B+2%3F%0A'
   11     2        INIT_METHOD_CALL                                         !0, 'get'
          3        DO_FCALL                                      0  $2      
          4        INIT_METHOD_CALL                                         $2, 'the'
          5        DO_FCALL                                      0  $3      
          6        INIT_METHOD_CALL                                         $3, '_answer'
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   12     9        INSTANCEOF                                               !0, 'AnswerInterface'
         10      > JMPZ                                                     ~6, ->13
   13    11    >   CONCAT                                           ~7      !1, '%0A'
         12        ECHO                                                     ~7
   15    13    > > RETURN                                                   null

End of function __construct

End of class Question.

Class AnswerInterface:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/drHBY
function name:  get
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E > > RETURN                                                   null

End of function get

Function the:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/drHBY
function name:  the
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E > > RETURN                                                   null

End of function the

Function _answer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/drHBY
function name:  _answer
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E > > RETURN                                                   null

End of function _answer

End of class AnswerInterface.

Class Answer:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/drHBY
function name:  get
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_THIS                                       ~0      
          1      > RETURN                                                   ~0
   30     2*     > RETURN                                                   null

End of function get

Function the:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/drHBY
function name:  the
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_THIS                                       ~0      
          1      > RETURN                                                   ~0
   35     2*     > RETURN                                                   null

End of function the

Function _answer:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/drHBY
function name:  _answer
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E > > RETURN                                                   4
   40     1*     > RETURN                                                   null

End of function _answer

End of class Answer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.73 ms | 1390 KiB | 13 Q