Guest User

Untitled

a guest
Jun 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class myGlobals {
  2.  
  3. static $myVariable;
  4.  
  5. }
  6.  
  7. function a() {
  8.  
  9. print myGlobals::$myVariable;
  10.  
  11. }
  12.  
  13. // in global space
  14. $myVar = "hello";
  15.  
  16. // inside a function
  17. function foo() {
  18. echo $GLOBALS['myVar'];
  19. }
  20.  
  21. $GLOBALS['_MYVAR'] = 'foo';
  22.  
  23. print_r($_MYVAR);
  24.  
  25. Class Registry {
  26. private $vars = array();
  27. public function __set($index, $value){$this->vars[$index] = $value;}
  28. public function __get($index){return $this->vars[$index];}
  29. }
  30. $registry = new Registry;
  31.  
  32. function _REGISTRY(){
  33. global $registry;
  34. return $registry;
  35. }
  36.  
  37. _REGISTRY()->sampleArray=array(1,2,'red','white');
  38.  
  39. //_REGISTRY()->someOtherClassName = new className;
  40. //_REGISTRY()->someOtherClassName->dosomething();
  41.  
  42. class sampleClass {
  43. public function sampleMethod(){
  44. print_r(_REGISTRY()->sampleArray); echo '<br/>';
  45. _REGISTRY()->sampleVar='value';
  46. echo _REGISTRY()->sampleVar.'<br/>';
  47.  
  48. }
  49. }
  50.  
  51. $whatever = new sampleClass;
  52.  
  53. $whatever->sampleMethod();
  54.  
  55. class myGlobals {
  56.  
  57. public static $myVariable;
  58.  
  59. }
  60.  
  61. function Test()
  62. {
  63. echo myGlobals::$myVariable;
  64. }
Add Comment
Please, Sign In to add comment