php php中require和require_once的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27867485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:34:50  来源:igfitidea点击:

the differences between require and require_once in php

php

提问by Ravi Mane

the difference between require and require_once. I just want to know the difference rather than Warning and Fatal Error in php.

require 和 require_once 的区别。我只想知道区别而不是 php 中的警告和致命错误。

回答by Neat

require()includes and evaluates a specific file, while require_once()does that only if it has not been included before (on the same page).

require()包含并评估特定文件,而require_once()仅在之前(在同一页面上)未包含该文件时才执行此操作。

So, require_once()is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.

因此,例如,require_once()当您要包含具有很多功能的文件时,建议使用。通过这种方式,您可以确保不会多次包含该文件,并且不会出现“重新声明函数”错误。

Source

来源