0

私はこれを持っていました:

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();
 }

}

「 Only variables can pass by reference」というエラーが表示されます。

どうしたの?

更新: エラー:「変数のみを参照で渡すことができます」は、次の行に関連しています:

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

どうもありがとう、MEM

4

1 に答える 1

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)

同じ名前の既存の変数を上書きしないように注意してください。

于 2010-12-17T11:43:18.480 に答える