Re: Re: How Do I make Global Scope Variables Available toFunctions

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

 



On Tue, 2018-05-29 at 13:02 +0200, Christoph M. Becker wrote:
> On 29.05.2018 at 02:51, John wrote:
> 
> > Thanks to all of you who suggested this link.  Unfortunately it doesn't
> > actually
> > work.  If I set the variable as:
> > 
> > global $bad_line = "This line ......";
> > 
> > I get error:
> > 
> > [Mon May 28 20:28:48.491851 2018] [proxy_fcgi:error] [pid 7502:tid
> > 139838662719232] [client 192.168.1.118:53916] AH01071: Got error 'PHP
> > message:
> > PHP Parse error:  syntax error, unexpected '=', expecting ',' or ';' in
> > /httpd/iliffe/yrarc/test.php on line 3\n'
> 
> This is expected, since the global statement does not support initializers.
> 
> > If I code it this way:
> > 
> > global $bad_line;
> > $bad_line = "This line ......";
> > 
> > then I get:
> > 
> > [Mon May 28 20:31:25.553000 2018] [proxy_fcgi:error] [pid 7502:tid
> > 139838662719232] [client 192.168.1.118:53916] AH01071: Got error 'PHP
> > message:
> > PHP Notice: Undefined variable bad_line in /httpd/iliffe/yrarc/test.php on
> > line
> > 9\n'
> > 
> > Looking at the reference, this is "inside out"; that is, the variable is
> > already
> > defined in the global scope, that is it is in the scope of <?php ....?> and
> > I
> > want it to be available inside the function.  The reference is for variables
> > defined within a function to make them available outside the function
> > scope. 
> 
> The global statement is supposed to be used inside a function body, and
> it creates a local variable which is actually a reference to the global
> variable with the same name.  It does not matter if the global variable
> is already set or not.
> 
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!

Regards,

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