ID:               18480
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Closed
 Bug Type:         Documentation problem
 Operating System: all
 PHP Version:      4.2.1


Previous Comments:
------------------------------------------------------------------------

[2002-07-23 10:40:46] [EMAIL PROTECTED]

gosh, and how would the KeepVariables() function know to access the
*global* variables $a and $b if you didn't tell it to?

this is IMO just a matter of common sense, so please, stop this
thread.



------------------------------------------------------------------------

[2002-07-23 10:27:56] [EMAIL PROTECTED]

Yes. I knew I had to declare the var as global is the function where I
wanted to use it. What was not clear for me was that I  needed to
declare it as global in the two functions. If I take the functions from
the patch as example, declaring $a and $b as global in Sum() was
evident, but declaring them as global also in KeepVariables() was not
evident.

Of course, when you *know* it, it's clear, but when you don't know it,
and since the doc isn't IMHO clear about this, it's not evident at
all.

This patch should be more clear (hopefully):

Index: en/language/variables.xml
===================================================================
RCS file: /repository/phpdoc/en/language/variables.xml,v
retrieving revision 1.52
diff -u -r1.52 variables.xml
--- en/language/variables.xml   3 Jul 2002 22:51:23 -0000       1.52
+++ en/language/variables.xml   23 Jul 2002 14:26:36 -0000
@@ -375,8 +375,10 @@
     The above script will output "3".  By declaring
     <varname>$a</varname> and <varname>$b</varname> global within the
     function, all references to either variable will refer to the
-    global version.  There is no limit to the number of global
-    variables that can be manipulated by a function.
+    global version. In the same way, if you want to access in a
function
+    to a var from another function, declare it as global in both
functions.
+    There is no limit to the number of global variables that can be
+    manipulated by a function.
    </simpara>
 
    <simpara>

------------------------------------------------------------------------

[2002-07-22 19:05:35] [EMAIL PROTECTED]

I really don't understand why this point would have confused you.  The
only variables you can access inside a function are the variables local
to that specific function.  If you want to access a variable defined
outside of the function (ie. a global) you have to specify you want to
access that global variable.  There is no way for a function to access
another function's locally scoped variables.

------------------------------------------------------------------------

[2002-07-22 19:00:11] [EMAIL PROTECTED]

For me, the fact that it was needed to create a global variable in one
function to access to in another was not clear. Specially because it's
not the case for vars that are outside any function. I don't think it's
something evident.

My patch probably doesn't explain it well, I'll try to make one more
clear tomorrow (yup, it's damn too late here).

------------------------------------------------------------------------

[2002-07-22 18:54:14] [EMAIL PROTECTED]

That's not a different use though.  You are simply creating a global
variable in one function and accessing it in another.  I don't think
this patch clarifies anything.  Perhaps the fact that you can create
global variables inside a function is not documented well enough, but a
much simpler documentation fix can take care of that.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/18480

-- 
Edit this bug report at http://bugs.php.net/?id=18480&edit=1


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to