只有变量可以通过引用传递 - opensocket 问题
我有这个:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
&$errno
和&$errstr
参数通过引用传递。您不能在那里使用空字符串''
作为参数,因为这不是可以通过引用传递的变量。为这些参数传递一个变量名称,即使您对它们不感兴趣(不过您应该感兴趣):
请小心不要覆盖具有相同名称的现有变量。
The
&$errno
and&$errstr
parameters 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.