3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Interview code review assignment class Greeter { private static $sStart; private static $sEnd; /** * Sets the greeter's sentence * @param string $sentenceStart * @param string $sentenceEnd */ public static function setSentence(string $sentenceStart, string $sentenceEnd) { self::$sStart = $sentenceStart; self::$sEnd = $sentenceEnd; } public static function greet($name) { print self::$sStart . $name . self::$sEnd; } } Greeter::setSentence("Hello ", "!\n"); Greeter::greet("John"); // Outputs: "Hello John!\n" Greeter::setSentence("Have a nice day, ", "...\n"); Greeter::greet("Peter"); // Outputs: "Have a nice day, Peter...\n"
Output for hhvm-3.15.4, 7.0.0 - 7.2.6
Hello John! Have a nice day, Peter...
Output for 5.6.0 - 5.6.30
Catchable fatal error: Argument 1 passed to Greeter::setSentence() must be an instance of string, string given, called in /in/KDnkY on line 27 and defined in /in/KDnkY on line 15
Process exited with code 255.