How do I pass undefined vars to functions without E_NOTICE errors?

前端 未结 4 1780
深忆病人
深忆病人 2020-12-20 12:48

Pretty simple question really, how do I pass undefined vars to functions without E_NOTICE errors?

When passing undefined variables to functions such as isset(), no e

4条回答
  •  长情又很酷
    2020-12-20 13:18

    isset is a bit special as it is actually a PHP language construct rather than a function [1].

    If a variable is undefined, you can't really pass it because it isn't defined (hence the warning).

    As stated in comments, you can suppress the warnings by prepending an @ to the variable which will prevent a warning from being emitted if it is not set. Then within the function you can check to see if the value is null or try using isset to see if it is registered.

提交回复
热议问题