summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Kaminski <kyle@xenomedia.com>2014-04-01 01:23:49 -0500
committerKyle Kaminski <kyle@xenomedia.com>2014-04-01 01:23:49 -0500
commit0a99c2a0a1a23f60e3472a00540fefb4ffed35fb (patch)
treec0999113aec8f5a7f173976555b4024032e03b32
parent73a386618382e3f701c83fa46f6846ce0e250c86 (diff)
parent7bf745c1f1701a85126ce3ff9e60cb078bbcd57a (diff)
downloadphpsandbox-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.php10
-rw-r--r--global_vars.php4
-rw-r--r--globals.php16
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;