lucerias Posted November 10, 2006 Share Posted November 10, 2006 May i know when to use global, when to use var? If let say i require x.php file into y.php file by using require syntax, and want to use the variable in the x.php file, do i have to declare again in y.php file or i can directly make use of it and then value can be passed from x.php to y.php? Thank you Link to comment https://forums.phpfreaks.com/topic/26784-global-declaration/ Share on other sites More sharing options...
btherl Posted November 10, 2006 Share Posted November 10, 2006 You don't need global when including files.You need global when you want to access a variable from inside a function. Eg[code=php:0]$var = 5;function foo() { global $var; print "var = $var\n";}[/code] Link to comment https://forums.phpfreaks.com/topic/26784-global-declaration/#findComment-122479 Share on other sites More sharing options...
lucerias Posted November 10, 2006 Author Share Posted November 10, 2006 If i use require or include method to include x.php into y.php, and then i include y.php into z.php, can i make use of the parameter stored in x.php with z.php? Thank you. Link to comment https://forums.phpfreaks.com/topic/26784-global-declaration/#findComment-122552 Share on other sites More sharing options...
btherl Posted November 10, 2006 Share Posted November 10, 2006 Yes you can. Try it and see for yourself :) Link to comment https://forums.phpfreaks.com/topic/26784-global-declaration/#findComment-122556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.