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 Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/290053-variable-scope/#findComment-1485888 Share on other sites More sharing options...
Solution requinix Posted July 22, 2014 Solution Share Posted July 22, 2014 (edited) 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)); Edited July 22, 2014 by requinix Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/290053-variable-scope/#findComment-1485915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.