James Allen
James Allen

Reputation: 47

PHP function parameters as parameters

protected function waitPage($URL) {
    $this->webDriver->wait(10,500)->until(function ($URL){
        return $this->webDriver->getCurrentURL() === $URL;
    });
}

Hey guys so that's my code, I'm trying to do end to end tests for a product. The internal function is part of the facebook webdriver where it is meant to wait until the URL changes to the new URL. I'm allowing an URL parameter to be passed, in order for the entire function just to be a little nicer in format.

However the internal function says that the $URL var wasnt declared and the outer function says that the $URL parameter isnt being used... I thought that the scope of the outer parameter would be within space in which the inner function can use it as a parameter.

Can anyone tell me why this doesn't work?

Thanks!

Upvotes: 1

Views: 54

Answers (1)

michaJlS
michaJlS

Reputation: 2500

You need to go for use:

protected function waitPage($URL) {
    $this->webDriver->wait(10,500)->until(function () use ($URL){
        return $this->webDriver->getCurrentURL() === $URL;
    });
}

as shown in manual in example #3

Upvotes: 2

Related Questions