I completely new to PHP. I have done something this:
class Foo
{
@BeforeSuite
public static function prePare()
{
$obj = new Foo;
$obj->iVisit("https://google.com");
}
}
public function iVisit($url)
{
if ($url != null) {
$this -> getSession() -> visit($url);
}
else {
throw new PendingException();
}
}
}
But it is throwing this error:
PHP Fatal error: Call to a member function getSession() on a non-object
Edited:
My scenario is to load a URL before other test cases start to run. So I choose to load the url in the @beforesuite
function, but in behat, @beforesuite
is a static function. I had to call the iVisit method from the static function.
Is there any other solution for this problem?
Its not a php concept, its just a programming concept.
You cannot just call a non static method anywhere, simply because you need to make an instance (or refer to a already present instance ) of that class to call the function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.