In PHP, how does include() exactly work?

后端 未结 5 1921
别那么骄傲
别那么骄傲 2020-12-18 01:18

How does include(\'./code.php\'); work? I understand it is the equivalent of having the code \"pasted\" directly where the include occurs, but, for example:

5条回答
  •  不思量自难忘°
    2020-12-18 01:47

    Include does not behave like copy paste.

    Here is a demonstration using PHP Strict Type Declarations

    However, if I call this function from an external file

    Strict types are enabled for the file that the declare statement was added (function.php)

    It does not apply for any function calls made from an external file (caller.php)
    because PHP will always defer to the caller when looking to evaluate strict types.

    Require doesn't work like copy/paste

    For further understanding,
    Short answer on how PHP script is Executed &
    A more comprehensible explanation on what include/require really does in php

提交回复
热议问题