<?php
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle): bool
{
return '' === $needle || false !== strpos($haystack, $needle);
}
};
$types = [
'string' => 'test',
'int' => 1,
'float' => 1.23,
'null' => null,
'true' => true,
'false' => false,
'object' => new StdClass(),
'array' => [],
];
$result = [
];
foreach($types as $type => $val)
{
try
{
$res = str_contains($val, 'test');
}
catch (Error $e)
{
$res = 'Fatal error triggered';
}
$result[$type] = $res;
}
var_export($result);
preferences:
25.02 ms | 407 KiB | 5 Q