PHP: What are language constructs and why do we need them?

后端 未结 7 846
时光取名叫无心
时光取名叫无心 2020-12-17 15:12

I keep coming across statements like:

  • \"echo is a language construct but print is a function and hence has a return value\"
  • \"die is a language constr
7条回答
  •  抹茶落季
    2020-12-17 15:58

    Language constructs are what makes up the language: things like "if" "for" "while" "function" and so on.

    The mentions in the PHP manual of things like "echo", "die" or "return" are there to make it clear that these are NOT functions and that they do not always behave like functions.

    You could call "echo" as "echo()" so it may confuse beginners. That's why they put the clear disinction in the manual. To make it absolutely clear to everyone.

    Other examples for language constructs that could be mistaken for functions are "array()", "list()" and "each()".

提交回复
热议问题