Function Variables

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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Function Variables

Post by Gen-ik »

I really should know this but is there a way of setting up a variable in PHP so that it can be read by any function.. without having to keep sending that variable to a function everytime it's called.

I know I could use classes but it's not worth the overhead for what I'm doing.

Basically if I set $MyName I would like to be able to access and change this variable from any where in the PHP code.. including functions().


Any ideas would be a big help.


Thanks.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

I don't know exectly but i think import_request_variables will do the trick.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

not sure if this is exactly what you want but you could use

$GLOBALS['MyName'] instead of $MyName

sorry dont know of any other way around it, besides declaring the variables as GLOBAL in all the functions.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Ahhh.. got it. I knew it would be simple. I'm using the global $MyName way of doing it in each of the functions.... seems like the easiest way.

Cheers guys.
Post Reply