maexus Posted April 8, 2008 Share Posted April 8, 2008 In your includes, do you generally have longer more complex variable names or use unset for variables that aren't needed outside the include to prevent conflict of variables in the script calling the include? In case that didn't make sense... consider the following somefile.inc.php: <?php $paths = array('dir', 'dir2', 'dir3'); $base = dirname(__FILE__); foreach($paths as $path){ $files = glob("{$base}/{$path}/*.ext"); foreach($files as $file){ require_once($file); } } ?> index.php: <?php require_once("somefile.inc.php"); $paths = "another variable used for a completely different reason than the one used in the included file"; ?> Now, this will work, $paths will just be reassign but personally, this looks just sloppy. I see two options. Instead of using $paths, I could have $jfw_plugin_paths or use unset($paths) at the end of the include file. Which method do you use or do you just let the variable be reassigned when it's needed. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted April 8, 2008 Share Posted April 8, 2008 Use classes and functions and stop putting things in the global namespace and you avoid this problem. This is why large chunks of procedural code become buggy and difficult to maintain. Quote Link to comment Share on other sites More sharing options...
maexus Posted April 8, 2008 Author Share Posted April 8, 2008 *edit* I'm going to try a different approach. Quote Link to comment Share on other sites More sharing options...
keeB Posted April 10, 2008 Share Posted April 10, 2008 Use classes and functions and stop putting things in the global namespace and you avoid this problem. This is why large chunks of procedural code become buggy and difficult to maintain. I smiled. And I agree. Quote Link to comment 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.