You are here: Re: how do you initialize global variables once? « PHP Programming Language « IT news, forums, messages
Re: how do you initialize global variables once?

Posted by s on 03/23/06 08:45

On Thu, 23 Mar 2006 06:16:42 GMT, Stephen Kay
<sk@karma-lab.nospam.com> wrote:

>Sorry fi this is a stupid question - I come from a c/c++ background, and the
>global variables in php aren't making sense to me.

You're fine, the only adjustment you need to make is that PHP
variables are neither typed nor (necessarily) declared by default.

>If I want to declare a global variable, say in a global.php file, and have
>it initialized to a certian value once, can that be done? Example:
>
>// in global.php
>
>$myvar = 25;
>
>// in some other file
>
>require ("global.php");
>
>function somefunction()
>{
> global $myvar;
>
> if ($myvar == 25){
> $myvar = 30;
> echo "setting myvar to 30.";
> }
>}
>
>
>So far, so good. I can access this variable in this other functions.
>
>But it doesn't seem to *stay* 30. It goes back to 25. Must be some other way
>to do this in php, but I haven't come across the documentation yet. Thanks
>for any info.

At what point in your code does it revert to 25? Do you have a
function somewhere that doesn't pull $myvar from the global scope?


--
<s@guerril.la.ape> (to email, remove .ape)
Apologies for the ad below.
--

*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***

 

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

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