dongtao9887 2019-05-21 06:41
浏览 22

描述模拟过载函数的最佳注释是什么?

I am using Visual Studio Code(VS Code), it can display the annotation of functios. I am try to improve write a PHPDoc standard. Can any suggestions to me? Thank you.

Here have 3 functions, but they are not the focal point . I just want to know how to write a PHPDoc standard describe the function 2 and simulation overload function 3.

Ref: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#54-examples

<?php

// Function 1:
/**
 * Check if A is equal to B.(Just a sample note, not important)
 *
 * @param string    A
 * @param string    B
 *
 * @return bool
 */
function checkAandB_1($a, $b){
    if($a === $b)
        return true;
    return false;
}

// Function 2:
/**
 * Check if A is equal to B.(Just a sample note, not important)
 *
 * @param string    Input x,y (<=here, I need to known how to write a right note to describe this function can support input a string combin x and y with a comma in one line)
 *
 * @return bool
 */
function checkAandB_2($str){
    if( substr_count($str, ",") === 1 ) {
        $strArr = explode(",",$str);
        if($strArr[0] === $strArr[1])
            return true;
    }
    return false;
}


// Function 3: Simulation a overload function
/**
 * Check if A is equal to B.(Just a sample note, not important)
 *
 * @param string    (What's the best annotation to describe this function?)
 *
 * @return bool
 */
function checkAandB_overload($str, $b = null){

    if(isset($b) && $str === $b){
        return true;
    }elseif( substr_count($str, ",") === 1 ) {
        $strArr = explode(",",$str);
        if($strArr[0] === $strArr[1])
            return true;
    }
    return false;
}



var_dump(checkAandB_1("1","2")); // false
var_dump(checkAandB_1("2","2")); // true

var_dump(checkAandB_2("1,2")); // false
var_dump(checkAandB_2("2,2")); // true

var_dump(checkAandB_overload("1","2")); // false
var_dump(checkAandB_overload("2","2")); // true
var_dump(checkAandB_overload("1,2")); // false
var_dump(checkAandB_overload("2,2")); // true
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 mmocr的训练错误,结果全为0
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀