3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * Challenge 2: Implement AnswerInterface and get Question to echo "4". */ class Question { public function __construct(AnswerInterface $answer) { echo "What is 2 + 2?\n"; $answer = $answer->get()->the()->answer(); if ($answer instanceof AnswerInterface) { echo $answer . PHP_EOL; } } } interface AnswerInterface { public function get(); public function the(); public function answer(); } // start editing here class Answer implements AnswerInterface { public function __toString() { return "4"; } public function get() { return $this; } public function the() { return $this; } public function answer() { return $this; } } // end editing here $answer = new Answer; $question = new Question($answer);
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/ucjhG
function name:  (null)
number of ops:  13
compiled vars:  !0 = $answer, !1 = $question
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   NOP                                                      
  18     1        NOP                                                      
  26     2        DECLARE_CLASS                                    $4      '%00answer%2Fin%2FucjhG0x7f441b58530d', 'answer'
         3        ADD_INTERFACE                                            $4, 'AnswerInterface'
         4        VERIFY_ABSTRACT_CLASS                                    $4
  46     5        NEW                                              $5      :-2
         6        DO_FCALL                                      0          
         7        ASSIGN                                                   !0, $5
  47     8        NEW                                              $8      :0
         9        SEND_VAR_EX                                              !0
        10        DO_FCALL                                      0          
        11        ASSIGN                                                   !1, $8
        12      > RETURN                                                   1

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

End of function __construct

End of class Question.

Class AnswerInterface:
Function get:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/ucjhG
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
Jump found. Position 1 = -2
filename:       /in/ucjhG
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
Jump found. Position 1 = -2
filename:       /in/ucjhG
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 __tostring:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/ucjhG
function name:  __toString
number of ops:  2
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  28     0  E > > RETURN                                                   '4'
  29     1*     > RETURN                                                   null

End of function __tostring

Function get:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/ucjhG
function name:  get
number of ops:  2
compiled vars:  !0 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  32     0  E > > RETURN                                                   !0
  33     1*     > RETURN                                                   null

End of function get

Function the:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/ucjhG
function name:  the
number of ops:  2
compiled vars:  !0 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  36     0  E > > RETURN                                                   !0
  37     1*     > RETURN                                                   null

End of function the

Function answer:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/ucjhG
function name:  answer
number of ops:  2
compiled vars:  !0 = $this
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  40     0  E > > RETURN                                                   !0
  41     1*     > RETURN                                                   null

End of function answer

End of class Answer.

Generated using Vulcan Logic Dumper, using php 7.2.0