3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Text { protected $text; public function __construct(string $text) { $this->text = $text; } /* public function __toString(): string { return $this->text; } */ public function get(): string { return $this->text; } } class Say { public function greet(string $name) { echo "Hello {$name}!"; } } $bob = new Text('Bob'); $say = new Say(); $say->greet($bob);
based on XK0rb
Output for 7.0.0 - 7.3.0rc3
Fatal error: Uncaught TypeError: Argument 1 passed to Say::greet() must be of the type string, object given, called in /in/n8UZ7 on line 30 and defined in /in/n8UZ7:22 Stack trace: #0 /in/n8UZ7(30): Say->greet(Object(Text)) #1 {main} thrown in /in/n8UZ7 on line 22
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught TypeError: Argument 1 passed to Say::greet() must be an instance of string, Text given in /in/n8UZ7:24 Stack trace: #0 /in/n8UZ7(30): Say->greet() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/n8UZ7 on line 16
Process exited with code 255.