HTML in PHP

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

[edit]
2 Minutes after I posted this i figured it out
However, I came up with a new question!
What's the difference between global(), include() and require()
Thanks

Laughing out loud

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Is this the global you mean?
http://www.php.net/manual/en/language.variables.scope.php

include vs require, the short version:
include()
include inserts the source code for a file when the include() call is read. If the file cannot be included, an error will be printed an error will be printed and the script will continue. If the include() statement is within IF statements, the file will only be included if the IF statement evaluates to true.

require()
require() inserts the source code for the file prior to processing. If the file cannot be inserted, the script will not continue. If the require() call is within IF statements, the file will be required regardless of wether the IF statment evaluates to TRUE or not.

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 157 posts

Joined: Mar 2002

Global is an easy one.

Just use include() always unless you absolutely need to require() a file somewhere no matter what.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Because require() inserts the contents of a file before processing, it comes in handy when you need to include stuff like common variables needed for a script in that page. Thats the most common use I have for it.

Otherwise, as theprofessional says, use include(). Wink

They have: 601 posts

Joined: Nov 2001

Are these similar to 'use' and 'require' in Perl? In Perl, require is pulled in when needed, where an use block is evaluated at compile time?

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

sounds like it

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

also... global isn't really a function, it's a declaration that defines the variables scope.

They have: 601 posts

Joined: Nov 2001

Yeah, I gathered that. Similar to when using 'use strict' in Perl, you have to define global, local variables etc.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.