testFunction((string)$ variable); - 这个叫什么?

时间:2014-10-21 18:51:45

标签: php casting

我看过一些像这样写的代码,我真的好奇它的作用和它的作用。抱歉标题不清楚,我感谢所有答案!

编辑:特别是我对(string) $variable部分

感到好奇

2 个答案:

答案 0 :(得分:1)

它被称为type casting

  

PHP中的类型转换与C中的类型转换一样:所需类型的名称在要转换的变量之前写在括号中。

<?php
$foo = 10;   // $foo is an integer
$bar = (boolean) $foo;   // $bar is a boolean
?>
The casts allowed are:

(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)

在您的具体示例中,变量被转换为字符串,然后作为参数传递给testFunction()

答案 1 :(得分:0)

这是一个带参数的函数调用。在这种情况下,变量$variable已被强制转换为参数的字符串。

相关问题