<?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);
- Output for 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
- Deprecated: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in /in/LPetC on line 31
array (
'string' => true,
'int' => false,
'float' => false,
'null' => false,
'true' => false,
'false' => false,
'object' => 'Fatal error triggered',
'array' => 'Fatal error triggered',
)
- Output for 8.0.0 - 8.0.30
- array (
'string' => true,
'int' => false,
'float' => false,
'null' => false,
'true' => false,
'false' => false,
'object' => 'Fatal error triggered',
'array' => 'Fatal error triggered',
)
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
- array (
'string' => true,
'int' => false,
'float' => false,
'null' => 'Fatal error triggered',
'true' => false,
'false' => false,
'object' => 'Fatal error triggered',
'array' => 'Fatal error triggered',
)
preferences:
73.4 ms | 409 KiB | 5 Q