/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] confuse between include and require

Hello everyone.

Up until now I’m confuse what is the main difference of include and require. As far as I know, include returns a warning while require return a fatal error, both when an error is detected. Can someone clarify me on between these too?

Huge thanks guys.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperJan 22.2010 — From php.net's help on include:

The [B]include()[/B] construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error. [/QUOTE]

The key being if it cannot find the filespec.

My informal advice is to research the other forms of each, i.e. include_once and require_once and also learn how to set the include_path to really simplify things.

-jim
Copy linkTweet thisAlerts:
@JerailJan 22.2010 — When deciding which to use, I usually ask myself: will the script still run alright if the file for some reason can't be included?

If it's absolutely required for the functioning of the website, then use require(). If it's some that's optional, and you don't want your users to receive a fatal error by some fluke instead of seeing the website, then use include().
Copy linkTweet thisAlerts:
@kingdmauthorJan 22.2010 — Thanks for the replies.

When deciding which to use, I usually ask myself: will the script still run alright if the file for some reason can't be included?

If it's absolutely required for the functioning of the website, then use require(). If it's some that's optional, and you don't want your users to receive a fatal error by some fluke instead of seeing the website, then use include().[/QUOTE]


Thanks professor ?
×

Success!

Help @kingdm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...