PHP 7是否支持资源的严格类型?如果是,该如何实现?
例如:
declare (strict_types=1);
$ch = curl_init ();
test ($ch);
function test (resource $ch)
{
}
以上代码将报错:
对Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of resource, resource given
$ch
进行var_dump()
,发现它是resource(4, curl),并且手册上说curl_init ()
会返回一个资源(resource)。是否有可能在
test()
函数中使用强类型支持$ch变量
?