1

以下の PHP 関数は、次のエラーを生成しています: 解析エラー: 構文エラー、予期しない '('、T_STRING または T_VARIABLE または '$' を期待しています。throw new ( '' . 'Illigal name for service name "' . $name . '" is given' );

誰が何が悪いのか知っていますか?

function registerService($name, $provider) {
    if (strlen( $name ) < 1) {
        Exception;
        throw new ( '' . 'Illigal name for service name "' . $name . '" is given' );
    }

    $this->_Services[$name] = $provider;
}

ありがとう

4

1 に答える 1

1

これを変える:

    Exception;
    throw new ( '' . 'Illigal name for service name "' . $name . '" is given' );

これに:

throw new Exception('Illegal name for service name "' .$name .'" is given' );

また、通常、try catch ブロックで例外をスローします。

try {
    throw new Exception('Just testing');
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
//Output: Caught exception: Just testing
于 2013-01-30T00:27:26.127 に答える