Let's say I have static connector that allows to proxy instances of different adapters:
$m = Connector::take('mcrouter');
$db = Connector::take('production_database');
Connector must init and handle connections during the runtime:
protected $connection;
abstract protected function openConnection($config);
Somewhere inside adapter:
$this->connection = $this->openConnection($config);
The connection is an object and could be an instance of Memcached, MySQLi etc. or NULL. So logically I want to do this:
protected ?object $connection;
abstract protected function openConnection($config):?object;
But at the same time connection is not really instance of "object", it is instance of Memcached for example, and the result is:
Catchable fatal error: Hack type error: Invalid assignment
The only solution works in this case is to not define the type at all. Is there are some trick for defining universal object?