<?php function castToString(Stringable|string $variable): string { try { $value = (string) $variable; } catch(\Throwable) { var_dump("Error thrown during string-conversion!"); $value = ''; } return $value; } class MyString { public function __toString(): never { throw new \Exception(); } } castToString(new MyString());
You have javascript disabled. You will not be able to edit any code.