误报。目前尚不清楚您使用的是哪个版本的 phpseclib,但我们假设您使用的是最新的 2.0 版本 (2.0.34)。 call_user_func 仅出现在第 2946 行:
https://github.com/phpseclib/phpseclib/blob/2.0.34/phpseclib/Net/SSH2.php#L2946
default:
if (is_callable($callback)) {
if (call_user_func($callback, $temp) === true) {
$this->_close_channel(self::CHANNEL_EXEC);
return true;
}
} else {
$output.= $temp;
}
它在 exec() 方法中。 $callback 是一个参数,其用途在 https://phpseclib.com/docs/commands#callbacks 中讨论。 3.0 分支使用$callback($temp) 而不是callback_user_func($temp),但基本思想相同。 $callback($temp) 可能不适用于旧版本的 PHP,而 callback_user_func($temp) 可以。
call_user_func_array 在 SSH2.php 中被调用了两次。一次是line 2227,一次是line 3375。
第 2227 行在 login 方法中。该方法的作用如下:
function login($username)
{
$args = func_get_args();
$this->auth[] = $args;
// try logging with 'none' as an authentication method first since that's what
// PuTTY does
if (substr($this->server_identifier, 0, 15) != 'SSH-2.0-CoreFTP' && $this->auth_methods_to_continue === null) {
if ($this->_login($username)) {
return true;
}
if (count($args) == 1) {
return false;
}
}
return call_user_func_array(array(&$this, '_login'), $args);
}
在 phpseclib 3.0.11 中,它正在执行 return $this->sublogin($username, ...$args);,但基本思想是它获取 $args 的每个元素并将其作为单独的参数传递给 $this->_login。就像你做了$this->_login($args) 那么_login 只会采用一个参数。 PHP 5.6 introduced the splat (...) operator 但 phpseclib 2 在 PHP 5.3 上运行,因此您必须执行 call_user_func_array 或仅使用单个参数即可。
这是call_user_func_array 的另一个实例:
function _reconnect()
{
$this->_reset_connection(NET_SSH2_DISCONNECT_CONNECTION_LOST);
$this->retry_connect = true;
if (!$this->_connect()) {
return false;
}
foreach ($this->auth as $auth) {
$result = call_user_func_array(array(&$this, 'login'), $auth);
}
return $result;
}
同样的事情。
所以就像我说的,这是一个空无一物的三明治。误报。