Hello all,
I have this singleton connection class to a socket:
final public function __construct()
{
$this->_host = 'ssl://example.hlp';
$this->_porto = 1231;
try
{
$filePointer = fsockopen($this->_host, $this->_porto);
//this will return a resource of stream type.
//var_dump($filePointer);
if ($filePointer === FALSE)
{
throw new Exception('error. OMG!!! OMG!!!!.');
}
else
{
return $filePointer;
}
}
catch(Exception $e)
{
echo "Erro de Conexão: " .$e->getMessage();
}
}
public static function getInstance()
{
if (self::$_instance === null)
{
self::$_instance = new self;
}
return self::$_instance;
}
I have an abstract class like so:
public function __construct()
{
require_once("Conexao.class.php");
$this->_filePointer = Conexao::getInstance();
//this->_filePointer is an OBJECT not a resource stream anymore.
//var_dump($this->_filePointer);
}
I know, even the method calls himself getINSTANCE so an object should be expected but I need a stream not an object, so that I can user $this->_filePointer AS A filePointer on other methods on this abstract class that will use fwrite for example.
What can I do?
Do I need to restructure this class relations somehow?
Can I have any help please. Again.
K. Regards,
Márcio