如果我创建一个 PDO 实例然后调用 PDO->Quote('test') 它没有问题。
如果我查看 PDO Quote 方法的定义,它看起来像这样:
/**
* Quotes a string for use in a query.
* PDO::quote() places quotes around the input string (if required) and escapes special characters within the input string, using a quoting style appropriate to the underlying driver.
*
* @param string $string The string to be quoted.
* @param int $parameter_type Provides a data type hint for drivers that have alternate quoting styles.
*
* return string
*/
function quote(string $string, int $parameter_type) {/* method implementation */}
请注意,参数实际上具有在方法签名、字符串和 int 中定义的类型。
现在,如果我创建这样的函数:
function Test(string $test) {
return $test;
}
并尝试这样称呼它:
echo Test('test');
它失败并出现以下错误:
( ! ) Catchable fatal error: Argument 1 passed to Test() must be an instance of string, string given, called in [path_removed]TestTypeHinting.php on line 36 and defined in [path_removed]TestTypeHinting.php on line 2
为什么PDO可以做到,但我不能?
问候,
斯科特