diff options
author | Kyle Kaminski <kyle@xenomedia.com> | 2014-04-01 01:23:49 -0500 |
---|---|---|
committer | Kyle Kaminski <kyle@xenomedia.com> | 2014-04-01 01:23:49 -0500 |
commit | 0a99c2a0a1a23f60e3472a00540fefb4ffed35fb (patch) | |
tree | c0999113aec8f5a7f173976555b4024032e03b32 | |
parent | 73a386618382e3f701c83fa46f6846ce0e250c86 (diff) | |
parent | 7bf745c1f1701a85126ce3ff9e60cb078bbcd57a (diff) | |
download | phpsandbox-0a99c2a0a1a23f60e3472a00540fefb4ffed35fb.tar.gz phpsandbox-0a99c2a0a1a23f60e3472a00540fefb4ffed35fb.tar.bz2 phpsandbox-0a99c2a0a1a23f60e3472a00540fefb4ffed35fb.zip |
Merge branch 'master' of 192.168.2.103:/srv/git/phpsandbox
-rw-r--r-- | global_from-func-to-global.php | 10 | ||||
-rw-r--r-- | global_vars.php | 4 | ||||
-rw-r--r-- | globals.php | 16 |
3 files changed, 30 insertions, 0 deletions
diff --git a/global_from-func-to-global.php b/global_from-func-to-global.php new file mode 100644 index 0000000..94d3f81 --- /dev/null +++ b/global_from-func-to-global.php @@ -0,0 +1,10 @@ +<?php + +function foo() { + global $foo; + $foo = 'bar'; +} + +foo(); +// prints 'bar' +echo $foo; diff --git a/global_vars.php b/global_vars.php new file mode 100644 index 0000000..bf86e98 --- /dev/null +++ b/global_vars.php @@ -0,0 +1,4 @@ +<?php + +$fruit = 'apple'; +$color = 'green'; diff --git a/globals.php b/globals.php new file mode 100644 index 0000000..ade8d6d --- /dev/null +++ b/globals.php @@ -0,0 +1,16 @@ +<?php +/* + * + */ + +function foo() { + // when a file is included, the code it contains inherits the variable scope of the line on which the include occurs + include 'global_vars.php'; + echo $color; +} + +// prints green +foo(); + +// undefined +echo $color; |