3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringLike { public $value; public function __construct($value) { $this->value = $value; } public function __toString() { return $this->value; } } $haystack = new StringLike('foo'); $needle = 'o'; echo mb_strlen($haystack), "\n"; echo mb_strpos($haystack, $needle), "\n"; $haystack = 123; $needle = 2; echo mb_strlen($haystack), "\n"; echo mb_strpos($haystack, $needle), "\n"; $haystack = null; $needle = 'bar'; echo mb_strlen($haystack), "\n"; echo mb_strpos($haystack, $needle), "\n";

preferences:
130.02 ms | 405 KiB | 5 Q