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 */}
パラメーターには、実際にはメソッド シグネチャ、string、および 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 ではできるのに、私にはできないのでしょうか?
よろしく、
スコット