PHP中的递归stripslashes方法疑难解答

Vir*_*dia 1 php

我试图在PHP文档中使用stripslashes_deep函数作为方法,但是当我将它传递给数组时,它不起作用.但是,它确实可以使用字符串.任何人都可以指出为什么它可能无法正常工作?魔术引号是因为我正在测试这种可能性,但就像我说的那样,它适用于字符串而且我也没有测试$ _POST或$ _GET数据.这是代码:

protected function stripslashes_deep($input){
    return is_array($input) ? array_map($this->stripslashes_deep, $input) : stripslashes($input);
}
Run Code Online (Sandbox Code Playgroud)

字符串'O \'Reilly'被转换为'O'Reilly',但下面的数组保持不变:

数组([0] =>数组([userId] => 23 [0] => 23 [用户名] => O \'Reilly [1] => O \'Reilly [userFirstName] => Bill [2] => Bill [userLastName] => O \'Reilly [3] => O \'Reilly))

任何帮助将不胜感激.

编辑:

该数组来自数据库并具有斜杠,因为它是由PDO对象插入的绑定参数.我扩展了PDO,我试图在获取数组时自动去除斜杠,所以我不必每次输出数据时调用stripslashes.如果有人知道更好的方法,我肯定会接受建议.我没有看到任何类型的PDO的非引用方法.

tro*_*skn 8

array_map($this->stripslashes_deep, $input) : stripslashes($input);
Run Code Online (Sandbox Code Playgroud)

应该:

array_map(array($this, 'stripslashes_deep'), $input) : stripslashes($input);
Run Code Online (Sandbox Code Playgroud)

如果你打算撤消魔术引号,你不应该以递归的方式实现它,因为它有一些性能和安全问题.见:http://talks.php.net/show/php-best-practices/26