Skip to content

Instantly share code, notes, and snippets.

@MasterEx
Created July 20, 2011 20:31
Show Gist options
  • Save MasterEx/1095856 to your computer and use it in GitHub Desktop.
Save MasterEx/1095856 to your computer and use it in GitHub Desktop.
PHP - include global configuration variables to functions and classes
<?php
//way 1
$bla = "tralala";
//way 2
$GLOBALS["blabla"] = "yoohoo";
?>
<?php
include("conf.php");
function foo() {
//way 1
global $bla;
echo $bla;
echo "<br/>";
//way 2
echo $GLOBALS["blabla"];
}
foo();
?>
<?php
include("conf.php");
class Bar {
function foo() {
//way 1
global $bla;
echo $bla;
echo "<br/>";
//way 2
echo $GLOBALS["blabla"];
}
}
$bar = new Bar;
$bar->foo();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment