php里面booler类型标识,PHP:bool与boolean类型提示

[HTTP://PHP.net/manual/恩/functions.arguments.PHP#functions.arguments.type-declaration]

警告

不支持上述标量类型的别名。 而是将它们视为类或接口名称。 例如,使用布尔值作为参数或返回类型将需要一个作为类或接口布尔值的实例而不是布尔类型的实例的参数或返回值:

(int), (integer) - cast to integer

(bool), (boolean) - cast to boolean

(float), (double), (real) - cast to float

(string) - cast to string

(array) - cast to array

(object) - cast to object

(unset) - cast to NULL (PHP 5)

上面的示例将输出:

致命错误:未捕获的TypeError:传递给test()的参数1必须是boolean的实例,给定boolean

简而言之,(int), (integer) - cast to integer

(bool), (boolean) - cast to boolean

(float), (double), (real) - cast to float

(string) - cast to string

(array) - cast to array

(object) - cast to object

(unset) - cast to NULL (PHP 5)是bool的别名,别名在类型提示中不起作用。

使用“真实”名称:bool

(int), (integer) - cast to integer

(bool), (boolean) - cast to boolean

(float), (double), (real) - cast to float

(string) - cast to string

(array) - cast to array

(object) - cast to object

(unset) - cast to NULL (PHP 5)和(int), (integer) - cast to integer

(bool), (boolean) - cast to boolean

(float), (double), (real) - cast to float

(string) - cast to string

(array) - cast to array

(object) - cast to object

(unset) - cast to NULL (PHP 5)之间没有相似之处。

类型提示类似于您正在告诉函数应该接受哪种类型。

类型转换是在类型之间“切换”。

允许的强制转换为:

(int), (integer) - cast to integer

(bool), (boolean) - cast to boolean

(float), (double), (real) - cast to float

(string) - cast to string

(array) - cast to array

(object) - cast to object

(unset) - cast to NULL (PHP 5)

在php类型转换中,(bool)和(boolean)是相同的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值