GLOBAL'ing functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

GLOBAL'ing functions

Post by phice »

I'm creating a large link indexing program.

What I want is to be able to allow the webmaster to copy a short code:

Code: Select all

<?php showlinks(4); ?>
and not have to include a file on each page.

Does GLOBAL have a function like this? That will be able to make a function global through the whole site?
Image Image
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

when you declare/set something as global, it is set that way for the life of the script (the time it takes to execute). therefore, just because you write:
global $someVar;
in one script, dosen't mean it is available to your entire site without some extra work.

also, you cannot declare a function as global. to solve your problem you will have to include the file that defines the function.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

That's what I was thinking.
Image Image
Post Reply