3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types = 1); class UString { private $string = null; public function __construct(string $string) { $this->string = $string; } public function __toString() { return $this->string; } } echo strlen(new Ustring('Class with __string method !'));
based on vbJ4u
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: strlen() expects parameter 1 to be string, object given in /in/AnZP8:20 Stack trace: #0 {main} thrown in /in/AnZP8 on line 20
Process exited with code 255.
Output for 5.3.18 - 5.6.21
Warning: Unsupported declare 'strict_types' in /in/AnZP8 on line 3 Catchable fatal error: Argument 1 passed to UString::__construct() must be an instance of string, string given, called in /in/AnZP8 on line 20 and defined in /in/AnZP8 on line 9
Process exited with code 255.