Jump to content

Newbie PHP questions: can I use include anywhere? + using global variables.


OM2

Recommended Posts

1. Can I use include anywhere?

I want to take out code in the middle of the page... and stick it into a separate file.

And just use include to include the code where the code was previously.

 

Is this OK to do?

Or should include statements be at the top of the page only?

 

2. What's the deal with global variables?

I declare a variable.

i can't access it from within a function: so I have to use

global $varname;

in the function.

 

I read on php.net that using global variables is bad practice and can lead to hard to track bugs.

And if possible, to use arrays instead.

Even if I use an array, how do I access the global variable(s)?

Pass the array in as a parameter?

I can't see how that makes it less prone to bugs?

 

Thanks.

 

 

OM

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.