[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)是相同的。