Php function argument error suppression, empty() isset() emulation

后端 未结 14 559
执笔经年
执笔经年 2021-01-11 17:32

I\'m pretty sure the answer to this question is no, but in case there\'s some PHP guru

is it possible to write a function in a way where invalid arguments or non exi

14条回答
  •  鱼传尺愫
    2021-01-11 18:07

    @Brian: I use a trinary operation to do the check for me:

    return $value ? $value : $default;
    

    this returns either $value OR $default. Depending upon the value of $value. If it is 0, false, empty or anything similar the value in $default will be returned.

    I'm more going for the challenge to emulate functions like empty() and isset()

提交回复
热议问题