Re: Re: How Do I make Global Scope Variables AvailabletoFunctions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2018-05-29 at 22:06 +0200, Christoph M. Becker wrote:
> On 29.05.2018 at 16:18, John wrote:
> 
> > Thanks for your reply Christoph.  From your and other comments it appears
> > that I
> > can't do what I was trying to do.  
> > 
> > On the one hand, it is satisfying that I wasn't making a mistake; on the
> > other,
> > I sure wish there was a way to avoid passing all these variables in PHP!  In
> > a
> > way it makes the "function" command far less valuable than it should be!
> 
> On the contrary, I'd say!  If I see a variable inside a function body, I
> almost immediately know that it is a local variable or a function
> parameter (or a superglobal), unless there is a global “declaration”.
> Even better, each time I add a global “declaration”, I'm reminded to
> think of a better way to express myself, and if I see a lengthy list of
> globals, I know that the code will be hard to maintain.  See also
> <http://wiki.c2.com/?GlobalVariablesAreBad>.
> 
Well, it's certainly one point of view, and I don't disagree with most of it.

On the other hand, I would assume that the word "global" really means global,
that is, in scope to the entire script, and I think most programming languages
with which I have worked follow this convention.  

It is necessary to be aware of the programme structure and define variables in
the proper scope - if the variable is local, then define it in local scope, if
it is required throughout the script or programme, then put it in global scope.

The reference you gave mentions that conflicts could occur with variable names
within a a function but I think this would simply hide the conflicting global
(but I confess to being unsure about that in PHP).  

For full disclosure here, I am not a programmer and never have been; simply run
a web site for a small publishing company and I am the sysadmin, web designer,
operator, network specialist and you name it.  I worked in IT in operations for
many years on IBM mainframes before I retired; I'm in my late 70's now and all
this is simply to keep me out of trouble!  There's nothing on earth more
terrifying that a bored retiree with time on his hands.

Thanks again.

John




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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux