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

后端 未结 7 861
时光取名叫无心
时光取名叫无心 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 16:00

    Some things are just not possible using normal functions, consider this snippet:

    list($el1, $el2) = array('el1', 'el2');

    What it does is it takes the elements from a non-associative array and assigns the values to the variables defined in the list() construct.

    Simply cannot be done with functions :)

    A more subtle example is issetand empty. Though they look like functions, they one thing that's not possible with functions alone – they do not generate "variable is undefined" or "undefined index" notices.

提交回复
热议问题