FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Interesting: including files in functions





imagefree
I have noticed something interesting: When you include the files from within a function, the variables used sitewide cannot be used inside the included file (unless defined GLOBAL in that function).

Did you ever notice it?
rvec
eeh did you ever hear about a variable scope?
http://nl3.php.net/manual/en/language.variables.scope.php
ThePolemistis
rvec wrote:
eeh did you ever hear about a variable scope?
http://nl3.php.net/manual/en/language.variables.scope.php


Don't take away his glory... let him be happy Smile
imagefree
rvec wrote:
eeh did you ever hear about a variable scope?
http://nl3.php.net/manual/en/language.variables.scope.php


well, this page (you refered to) doesnt describe anything (in official post only) about the use of variables in included files (that are included inside functions). Last day i realized it for the first time.
rvec
imagefree wrote:
rvec wrote:
eeh did you ever hear about a variable scope?
http://nl3.php.net/manual/en/language.variables.scope.php


well, this page (you refered to) doesnt describe anything (in official post only) about the use of variables in included files (that are included inside functions). Last day i realized it for the first time.

andrew at planetubh dot com wrote:
I created a function (safeinclude), which I use to include files; it does processing before the file is actually included (determine full path, check it exists, etc).

Problem: Because the include was occurring inside the function, all of the variables inside the included file were inheriting the variable scope of the function; since the included files may or may not require global variables that are declared else where, it creates a problem.


You're right about that it doesn't specifically address includes in the original text.
Hogwarts
imagefree wrote:
rvec wrote:
eeh did you ever hear about a variable scope?
http://nl3.php.net/manual/en/language.variables.scope.php


well, this page (you refered to) doesnt describe anything (in official post only) about the use of variables in included files (that are included inside functions). Last day i realized it for the first time.


Why does it need to? o_o

It already explains that the contents of functions are outside the variable scope of the rest of the code. Who cares about included code? It's not at all different to regular code, it's just in a different file. It really should be a simple conclusion to draw Sad
Related topics
Windows Tips&tricks!
How To : Secure Your PHP Website
Site Nav Suggestions...
PHP Tutorials
Repair windows Xp with the Recovery Console
how to burn unread able cd ?
Question about Including Files
Server Side Include (HTML in HTML)
My own game
Has anyone installed Moodle successfully?
PHP & FTP - How to detect the file type.
Best video making program
POST a form in the Same page
Getting a Domain
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.