What is the difference between PHP require and include?

后端 未结 7 937
时光说笑
时光说笑 2020-11-30 12:35

I know the basic usage of PHP require, require once, include and include once. But I am confused about when I should use them.

Example: I have 3 files, eg: settings.

7条回答
  •  醉酒成梦
    2020-11-30 12:59

    Difference:-

    include() Fetch data and load contain in current file and also load same file more than one time.

    include_once() work same as include() but we use include_once() if a file has already been included, it will not be included again. if use same file as multiple time in Like:- include_once 'setting.php'; use second time include_once 'settting.php'; ignore them.

    require() work same as include().

    require_once() if file has already included, it will not be included again.

    include() and include_once() produce warning and script will continue.

    require() and require_once() produce fatel error and stop the script.

    Better to use

    require_once() in your script.

提交回复
热议问题