2010-12-17 128 views
0

我有这样的:只有变量可以通过引用传递 - 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(); 
} 

} 

我m得到错误说:“只有变量可以通过引用传递。”

发生了什么事?

更新: 错误: “只有变量可以通过引用传递” 是关系到这条线:

$this->_filePointer = fsockopen($this->_host, $this->_porto, '', '', $this->_timeout); 

非常感谢, MEM

+1

(叹气)*你在哪一行*得到错误? – 2010-12-17 11:36:15

+0

@皮卡 - 谢谢。我已更新我的问题。 Ps-我需要那些'','',在那里吗? – MEM 2010-12-17 11:42:53

回答

3
fsockopen (string $hostname [, int $port = -1 [, int &$errno [, 
      string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]]) 

&$errno&$errstr参数通过引用传递。您不能使用空字符串''作为参数,因为这不是一个可以通过引用传递的变量。

传递一个变量名称为这些参数,即使你不感兴趣(你应该是,虽然):

fsockopen($this->_host, $this->_porto, $errno, $errstr, $this->_timeout) 

要小心,不要使用相同的名称覆盖现有的变数。