3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thing { public function __call($name, $params) { return 'foo'; } } function can_be_string($var) { return $var === null || is_scalar($var) || is_callable([$var, '__toString']); } $a = new Thing; var_dump(can_be_string($a)); (string) $a;
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
bool(true) Fatal error: Uncaught Error: Object of class Thing could not be converted to string in /in/4ttLv:19 Stack trace: #0 {main} thrown in /in/4ttLv on line 19
Process exited with code 255.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
bool(true) Recoverable fatal error: Object of class Thing could not be converted to string in /in/4ttLv on line 19
Process exited with code 255.
Output for 7.0.0 - 7.0.20
bool(true) Catchable fatal error: Object of class Thing could not be converted to string in /in/4ttLv on line 19
Process exited with code 255.

preferences:
173.3 ms | 401 KiB | 187 Q