I had this:
final public function __construct()
{
$this->_host = 'ssl://myserver.com';
$this->_porto = 700;
$this->_filePointer = false;
try
{
$this->_filePointer = fsockopen($this->_host, $this->_porto);
if ($this->_filePointer === FALSE)
{
throw new Exception('Cannot place filepointer on socket.');
}
else
{
return $this->_filePointer;
}
}
catch(Exception $e)
{
echo "Connection error: " .$e->getMessage();
}
}
But I would like to add a timeout option to this class so I’ve added:
final public function __construct()
{
$this->_host = 'ssl://myserver.com';
$this->_porto = 700;
$this->_filePointer = false;
$this->_timeout = 10;
try
{
$this->_filePointer = fsockopen($this->_host, $this->_porto, '', '', $this->_timeout);
if ($this->_filePointer === FALSE)
{
throw new Exception('Cannot place filepointer on socket.');
}
else
{
return $this->_filePointer;
}
}
catch(Exception $e)
{
echo "Connection error: " .$e->getMessage();
}
}
I’m getting an error saying: “Only variables can passed by reference.”
What’s going on?
Update:
The error: “Only variables can be passed by reference” is related to this line:
$this->_filePointer = fsockopen($this->_host, $this->_porto, '', '', $this->_timeout);
Thanks a lot,
MEM
The
&$errnoand&$errstrparameters are passed by reference. You can not use an empty string''as argument there, since this is not a variable that can be passed by reference.Pass a variable name for these parameters, even if you’re not interested in them (which you should be, though):
Be careful to not overwrite existing variables with the same name.