我有这个:
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();
}
}
但我想为这个类添加一个超时选项,所以我添加了:
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();
}
}
我收到一条错误消息:“只有变量可以通过引用传递。”
这是怎么回事?
更新: 错误:“只能通过引用传递变量”与此行有关:
$this->_filePointer = fsockopen($this->_host, $this->_porto, '', '', $this->_timeout);
非常感谢,MEM