Destramic Posted July 21, 2014 Share Posted July 21, 2014 is there a way of having set variables for a specific include?...maybe be easier for me to explain via code <?php $bee = 'yes'; include_one "a.php"; include_one "b.php"; // only b.php can grab $bee var ?> im wondering if I can only pass a var to b.php without a.php being able to use the var also? thanks guys Link to comment https://forums.phpfreaks.com/topic/290053-variable-scope/ Share on other sites More sharing options...
chrisrulez001 Posted July 22, 2014 Share Posted July 22, 2014 You could move the variable declaration after the first include. That way only b.php can access the variable. Link to comment https://forums.phpfreaks.com/topic/290053-variable-scope/#findComment-1485888 Share on other sites More sharing options...
requinix Posted July 22, 2014 Share Posted July 22, 2014 Something I've used many times is an include function. function include_clean(/* $file, array $args */) { if (func_num_args() > 1) { extract(func_get_arg(1)); } return include func_get_arg(0); } include_clean("a.php"); include_clean("b.php", array("bee" => $bee)); Link to comment https://forums.phpfreaks.com/topic/290053-variable-scope/#findComment-1485890 Share on other sites More sharing options...
Destramic Posted July 22, 2014 Author Share Posted July 22, 2014 @requinix thanks, that will work quite nicely Link to comment https://forums.phpfreaks.com/topic/290053-variable-scope/#findComment-1485915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.