2010-12-17 39 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) 

要小心,不要使用相同的名稱覆蓋現有的變數。