我刚刚更新了我的应用程序,使用PHP7 typehints作为标量类型.当我运行我的单元测试时,我收到了这个错误:
PHP Fatal error: Default value for parameters with a class type can only be NULL in xxx.PHP on line 23
public function call(string $url, integer $timeout = 30)
{
// some code...
}
如果我用int替换整数,则错误消失.我总是听说int和integer是相同的我在文档中没有看到任何与此相关的内容……
此外,((int)1)===((整数)1)返回true,再次表明int和integer是相同的
我用的是PHP 7.0.8
解决方法:
根据文档,这些是有效的类型:
Class/interface name
self
array
callable
bool
float
int
string
还有这个:
Warning
Aliases for the above scalar types are not supported. Instead, they
are treated as class or interface names. For example, using boolean as
a parameter or return type will require an argument or return value
that is an instanceof the class or interface boolean, rather than of
type bool.
资料来源:http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。