Initializing a controller that uses Selenium
I found two better alternatives.

1. Change $driver from protected to public

Then you can pass the $this object directly to initDriver:

PortalController

public $driver = null;  

public function main()
{
    //Before: $this-&gt;driver = Selenium::initDriver(array($this, "driver"));

    //After:
    Selenium::initDriver($this);
    ...
}


SeleniumUtility

public static function initDriver($thisObj)
{    
    //Now I can do the if null check here

    if (thisObj-&gt;driver === NULL) {
       $thisObj-&gt;driver = RemoteWebDriver::create(self::SELENIUM_SERVER_ADDRESS, DesiredCapabilities::firefox(), self::DRIVER_TIMEOUT);
    }
}




2. Use getter and setter

PortalController

protected $driver = null;  

public function getDriver()
{
    return $this-&gt;driver;
}

public function setDriver($driver)
{
    $this-&gt;driver = $driver;
}

public function main()
{
    //Before: $this-&gt;driver = Selenium::initDriver(array($this, "driver"));

    //After:
    Selenium::initDriver($this);
    ...
}


SeleniumUtility

public static function initDriver($thisObj)
{    
    //Now I can do the if null check here

    if (thisObj-&gt;getDriver() === NULL) {
        $thisObj-&gt;setDriver( RemoteWebDriver::create(self::SELENIUM_SERVER_ADDRESS, DesiredCapabilities::firefox(), self::DRIVER_TIMEOUT));
    }
}


But in my opinion it makes no sense to make the driver protected, so the first solution is faster and better. As long as we do not store any valuable information like passwords in the driver, keeping it public is perfectly OK.