freelance84 Posted July 7, 2011 Share Posted July 7, 2011 Not sure what to search in google here or php manual.... A variable ($foobar) is set in "fileA.php" FileA includes_once 'FileB.php' which in turn may or may not include_once 'FileC.php' or include_once 'FileD.php.' ( fileA |_fileB |_fileC |_fileD ) My question is, is $foobar going to accessible to all no matter how far down, or is there a limit? Link to comment https://forums.phpfreaks.com/topic/241343-grabbing-a-variable-from-a-parent-parent-file/ Share on other sites More sharing options...
AbraCadaver Posted July 7, 2011 Share Posted July 7, 2011 Yes it will be available in global scope (not inside of a function or class). Link to comment https://forums.phpfreaks.com/topic/241343-grabbing-a-variable-from-a-parent-parent-file/#findComment-1239725 Share on other sites More sharing options...
xyph Posted July 7, 2011 Share Posted July 7, 2011 You should always verify that it exists in those included pages before using it though if( isset($foobar) ) Link to comment https://forums.phpfreaks.com/topic/241343-grabbing-a-variable-from-a-parent-parent-file/#findComment-1239728 Share on other sites More sharing options...
AbraCadaver Posted July 7, 2011 Share Posted July 7, 2011 I should have also mentioned that it is always available in the $GLOBALS super global array, though using global vars is normally not the best practice. Link to comment https://forums.phpfreaks.com/topic/241343-grabbing-a-variable-from-a-parent-parent-file/#findComment-1239734 Share on other sites More sharing options...
freelance84 Posted July 8, 2011 Author Share Posted July 8, 2011 Thanks. Just checking really. So in theory a variable set in fileA could still be called on the 1000th sub file. Cheers. Link to comment https://forums.phpfreaks.com/topic/241343-grabbing-a-variable-from-a-parent-parent-file/#findComment-1239896 Share on other sites More sharing options...
xyph Posted July 8, 2011 Share Posted July 8, 2011 It's theoretically true, but very bad in practice. Imagine trying to debug an unexpected value of a variable set 1000 pages back Keeping in mind that any one of those 1000 pages could have changed the variable as well Link to comment https://forums.phpfreaks.com/topic/241343-grabbing-a-variable-from-a-parent-parent-file/#findComment-1239906 Share on other sites More sharing options...
freelance84 Posted July 8, 2011 Author Share Posted July 8, 2011 hahaha, yea true. I'm just crossing the t's and dotting the i's as i go along learning all of this. Link to comment https://forums.phpfreaks.com/topic/241343-grabbing-a-variable-from-a-parent-parent-file/#findComment-1240034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.