PHP捕获PHP中已求值函数的返回值


PHP Capture return value from a evaluated function in PHP

我正在使用facebookphp-webdriver进行web应用程序测试。网络驱动程序中有一个功能,其工作方式如下

$webdriver->wait($timeOut, $pollInterval)->until(
    //condition to wait
); 

这个"等待条件"作为一个方法传递,例如;

$val = WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::id("user"))

所以完整的代码块是这样的;

$webdriver->wait($timeOut, $pollInterval)->until(
    $val = WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::id("user"))
); 

然后我有另一种方法,比如;

function get($url, [few more params], $expectedCondition){
    //do some work here and execute below wait condition
    $webdriver->wait($timeOut, $pollInterval)->until(
        $expectedCondition //this executes fine
    ); 
}

我将把上述方法称为以下方法;get([other params],WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::id("user"))

正如您所看到的,上面的最后一个参数本身就是进入我的GET方法的方法调用。它将正常执行,如下

    $webdriver->wait($timeOut, $pollInterval)->until(
        $expectedCondition //this will basically executes WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::id("user")) properly
    );  

但是,在执行$expectedCondition之后,我无法获得返回值。

eval()不起作用

$return_value = $driver->wait()->until($expectedCondition)