3v4l.org

run code in 150+ 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 E extends Exception{ public function getAnswer($question) { $reflectionClass = new ReflectionClass('Question'); return $reflectionClass->getProperty('answer')->getValue(); } } $e = new E; // end editing here new Question($e);
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught ReflectionException: Cannot access non-public member Question::answer in /in/ZpPhl:27 Stack trace: #0 /in/ZpPhl(27): ReflectionProperty->getValue() #1 /in/ZpPhl(16): E->getAnswer(Object(Question)) #2 /in/ZpPhl(35): Question->__construct(Object(E)) #3 {main} thrown in /in/ZpPhl on line 27
Process exited with code 255.
Output for 5.1.2 - 5.1.6, hhvm-3.10.0 - 3.12.0
Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in /in/ZpPhl on line 27
Output for 5.2.0 - 5.6.28
Fatal error: Uncaught exception 'ReflectionException' with message 'Cannot access non-public member Question::answer' in /in/ZpPhl:27 Stack trace: #0 /in/ZpPhl(27): ReflectionProperty->getValue() #1 /in/ZpPhl(16): E->getAnswer(Object(Question)) #2 /in/ZpPhl(35): Question->__construct(Object(E)) #3 {main} thrown in /in/ZpPhl on line 27
Process exited with code 255.
Output for 5.0.3 - 5.1.1
Fatal error: Uncaught exception 'ReflectionException' with message 'Cannot access non-public member' in /in/ZpPhl:27 Stack trace: #0 /in/ZpPhl(27): ReflectionProperty->getValue() #1 /in/ZpPhl(16): E->getAnswer(Object(Question)) #2 /in/ZpPhl(35): Question->__construct(Object(E)) #3 {main} thrown in /in/ZpPhl on line 27
Process exited with code 255.
Output for 5.0.0 - 5.0.2
Fatal error: Uncaught exception 'ReflectionException' with message 'Cannot access non-public member' in /in/ZpPhl:27 Stack trace: #0 /in/ZpPhl(16): E->getAnswer() #1 /in/ZpPhl(35): Question->__construct(Object(Question)) #2 {main} thrown in /in/ZpPhl on line 27
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ZpPhl on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ZpPhl on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/ZpPhl on line 9
Process exited with code 255.