Created
July 20, 2011 20:31
-
-
Save MasterEx/1095856 to your computer and use it in GitHub Desktop.
PHP - include global configuration variables to functions and classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//way 1 | |
$bla = "tralala"; | |
//way 2 | |
$GLOBALS["blabla"] = "yoohoo"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("conf.php"); | |
function foo() { | |
//way 1 | |
global $bla; | |
echo $bla; | |
echo "<br/>"; | |
//way 2 | |
echo $GLOBALS["blabla"]; | |
} | |
foo(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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