php - Why can't you define a constant named EMPTY

后端 未结 4 978
无人及你
无人及你 2021-01-22 01:07

So... This is more of a curiosity, not a real problem. I don\'t get this:

Results in: Pars

4条回答
  •  粉色の甜心
    2021-01-22 01:31

    empty is not a function but a language construct (more like an operator than a function), which means it's resolved by the parser at parse time and not by the runtime. It's a reserved keyword and you cannot use it for anything yourself like function names, or constants.

    The reason empty cannot be a regular function is because it behaves differently. empty($undefined) would first resolve $undefined, throw an error, then pass null to empty; which is exactly the case empty is supposed to prevent, so it cannot play by the normal function invocation rules.

提交回复
热议问题