3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types = 1); class TheClass { /** @var int */ public $seven = 7; public function getFive(): int { return 5; } public static function getSevenStrangelyButSafely(?TheClass $object): int { return $object->seven ?? 7; } public static function getFiveUnsafely(?TheClass $object): int { return $object->getFive() ?? 5; } } $value = TheClass::getSevenStrangelyButSafely(null); $value = TheClass::getFiveUnsafely(null);
Output for 7.1.0 - 7.3.0beta1
Fatal error: Uncaught Error: Call to a member function getFive() on null in /in/3GaDe:19 Stack trace: #0 /in/3GaDe(24): TheClass::getFiveUnsafely(NULL) #1 {main} thrown in /in/3GaDe on line 19
Process exited with code 255.
Output for 7.0.0 - 7.0.27
Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /in/3GaDe on line 12
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function getFive() on a non-object (null)' in /in/3GaDe:-1 Stack trace: #0 /in/3GaDe(-1): TheClass::getFiveUnsafely() #1 {main}
Process exited with code 255.
Output for hhvm-3.21.3
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function getFive() on a non-object (null)' in /in/3GaDe:19 Stack trace: #0 /in/3GaDe(24): TheClass::getFiveUnsafely() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5
Fatal error: Uncaught Error: Syntax only allowed in Hack files (<?hh) or with -v Eval.EnableHipHopSyntax=true in /in/3GaDe:12 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Warning: Unsupported declare 'strict_types' in /in/3GaDe on line 1 Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/3GaDe on line 7
Process exited with code 255.