You are here: Re: Global variables « PHP Programming Language « IT news, forums, messages
Re: Global variables

Posted by Oli Filth on 09/26/06 23:23

Jerry Stuckle said the following on 26/09/2006 22:07:
> Charles O'Flynn wrote:
>> Thanks for the quick reply, Johnny, but I've been looking at the page you
>> refer to all afternoon and it doesn't seem to work for me. For instance,
>> (and I'm only illustrating the specific problem I seem to have
>> hereunder)...
>> ------------------------------------
>> $variable;
>>
>> function printsomething()
>> {
>> global $variable;
>>
>> $variable = 'Test'.<b />;
>> echo $variable;
>> }
>>
>> printsomething();
>> echo $variable;
>> ------------------------------------
>>
>> ...only prints one line of 'Test' - I'd have thought it should print
>> out two
>> copies. BTW, I'm running under PHP 4.1.2 (and it's not mine to
>> change/upgrade!)
>
> You're close. But you have to use the global keyword in the global
> context, also. Not just in the function.

Umm, no you don't!
http://uk.php.net/manual/en/language.variables.scope.php#language.variables.scope.global

>
> global $variable;
>
> function printsomething()
> {
> global $variable;
>
> $variable = 'Test'.<b />;
> echo $variable;
> }
>
> printsomething();
> echo $variable;
>


--
Oli

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация