Jump to content

variable scope


Destramic

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.