From 97d1e75a51d1754d243d3be36aa22ad63b28bdb2 Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Wed, 5 Mar 2014 15:44:17 +0100 Subject: [PATCH 1/3] Use call_user_func, as this will work on PHP < 5.4, whereas $callback() does not --- phpseclib/Net/SSH2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 2fddb68a..d3bc7c60 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2258,7 +2258,7 @@ class Net_SSH2 return false; default: if (is_callable($callback)) { - $callback($temp); + call_user_func($callback, $temp); } else { $output.= $temp; } From b5e579f6c05209360c31bd9b03c262f846232f76 Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Wed, 5 Mar 2014 18:38:33 +0100 Subject: [PATCH 2/3] Also replace this with call_user_func --- phpseclib/Net/SCP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Net/SCP.php b/phpseclib/Net/SCP.php index 4cfa3570..f66a535a 100644 --- a/phpseclib/Net/SCP.php +++ b/phpseclib/Net/SCP.php @@ -216,7 +216,7 @@ class Net_SCP $sent+= strlen($temp); if (is_callable($callback)) { - $callback($sent); + call_user_func($callback, $sent); } } $this->_close(); From 90ff32d56df26508cbab91c2e43048a09d83b160 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 6 Mar 2014 11:35:54 +0100 Subject: [PATCH 3/3] Tests for bug280. --- tests/Net/SSH2FunctionalTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Net/SSH2FunctionalTest.php b/tests/Net/SSH2FunctionalTest.php index 34a9377b..3078bd40 100644 --- a/tests/Net/SSH2FunctionalTest.php +++ b/tests/Net/SSH2FunctionalTest.php @@ -41,5 +41,21 @@ class Net_SSH2FunctionalTest extends PhpseclibFunctionalTestCase $ssh->login($username, $password), 'SSH2 login using password failed.' ); + + return $ssh; + } + + /** + * @depends testPasswordLogin + * @group bug280 + */ + public function testExecWithMethodCallback($ssh) + { + $callbackObject = $this->getMock('stdClass', array('callbackMethod')); + $callbackObject + ->expects($this->atLeastOnce()) + ->method('callbackMethod') + ->will($this->returnValue(true)); + $ssh->exec('ls', array($callbackObject, 'callbackMethod')); } }