From: [EMAIL PROTECTED]
Operating system: all
PHP version: 4.2.1
PHP Bug Type: Documentation problem
Bug description: Undocumented global use
One of the uses of "global $var;" seems not to be documented. Here's a tiny
patch to fix that.
--beginning--
Index: en/language/variables.xml
===================================================================
RCS file: /repository/phpdoc/en/language/variables.xml,v
retrieving revision 1.52
diff -u -u -r1.52 variables.xml
--- en/language/variables.xml 3 Jul 2002 22:51:23 -0000 1.52
+++ en/language/variables.xml 22 Jul 2002 22:34:16 -0000
@@ -380,6 +380,47 @@
</simpara>
<simpara>
+ Please note that if you want to access in your function to a
variable
+ which is in another function, all that through a global variable,
+ you'll need to declare it as a variable in the two functions.
+ An example, always with our function Sum():
+ </simpara>
+
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
+<?php
+
+function KeepVariables()
+{
+ global $a, $b;
+
+ $a = 1;
+ $b = 2;
+}
+
+function Sum()
+{
+ global $a, $b;
+
+ $b = $a + $b;
+}
+
+KeepVariables();
+Sum();
+echo $b;
+?>
+]]>
+ </programlisting>
+ </informalexample>
+
+ <simpara>
+ If we hadn't declared <varname>$a</varname> and
<varname>$b</vargame>
+ as globals in the KeepVariables() function, the script would have
+ displayed nothing.
+ </simpara>
+
+ <simpara>
A second way to access variables from the global scope is to use
the special PHP-defined <varname>$GLOBALS</varname> array. The
previous example can be rewritten as:
--end--
If it can be useful, I can also write a french version of it, since I'm
french.
HTH.
--
Edit bug report at http://bugs.php.net/?id=18480&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18480&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18480&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18480&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18480&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18480&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18480&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18480&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18480&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18480&r=globals
--
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php