PHP文档function()需要$ _GET参数

时间:2014-08-02 08:31:01

标签: php comments

我已使用此语法记录函数(示例)

/**
* Sum numbers
*
* @param  integer  $FirstNum   First  number to sum
* @param  integer  $SecondNum  Second number to sum
* @throws \Exception           If something's wrong
* @return integer              Sum of first and second number 
*/ 
function sum($FirstNum, $SecondNum){

    if( !is_number($FirstNum) )
        throw new Exception('FirstNum isn\'t a number');

    if( !is_number($SecondNum) )
        throw new Exception('SecondNum isn\'t a number');

    return $FirstNum + $SecondNum
}

我有一个函数读取查询字符串中的值,我想记录它。什么是最好的方式?

/**
* Sum numbers
*
* ??????????????????????????????????????????????????
* ??????????????????????????????????????????????????
* @throws \Exception           If something's wrong
* @return integer              Sum of first and second number 
*/ 
function sum(){

    $FirstNum  = isset($_GET['FirstNum'])  ? $_GET['FirstNum'] : null;
    $SecondNum = isset($_GET['SecondNum']) ? $_GET['SecondNum'] : null;

    if( !is_number($FirstNum) )
        throw new Exception('FirstNum isn\'t a number');

    if( !is_number($SecondNum) )
        throw new Exception('SecondNum isn\'t a number');

    return $FirstNum + $SecondNum
}

我不知道是否采用标准方式。我想到了这个解决方案:

/**
* @param  integer  $_GET['FirstNum']   First  number to sum
* @param  integer  $_GET['SecondNum']  Second number to sum

对不起我的谷歌翻译英语:(

0 个答案:

没有答案