php 7.0 typehint:整数和默认值的致命错误

我刚刚更新了我的应用程序,使用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是相同的我在文档中没有看到任何与此相关的内容……

PHP错误似乎说整数是一个类而不是标量类型.

此外,((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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...