You are here: Re: Var will not show up in globals!!?? « All PHP « IT news, forums, messages
Re: Var will not show up in globals!!??

Posted by Carl on 10/11/05 19:33

www.douglassdavis.com wrote:
> For example, if I put this code in a file called globaltest.php:
>
> $new_var="This is a string";
>
> class TestClass
> {
>
> function __construct()
> {
> global $new_var;
> echo "<br>new var: ".$new_var;
> }
>
> function testFunc()
> {
> global $new_var;
> echo "<br>new var in testFunc(): ".$new_var;
> echo "<br>from globals ".$GLOBALS['new_var'];
> }
> }
>
> $testo=new TestClass();
> $testo->testFunc();
>
> It displays
>
> new var: This is a string
> new var in testFunc(): This is a string
> from globals This is a string
>
> as it should.
>
> However, when I put it in another file that is an included php file, it
> doesn't even register new_var as a global, and I get this printed out:
>
> new var:
> new var in testFunc():
> from globals
>
> I don't understand. What could possibly be making this happen? Right
> now I am looking for any possibilities, because to me, it doesn't seem
> to make sense.

Are you including the include file in the global scope, outside of any
classes/methods?
Are you defining the variable you are attempting to access in the global
scope as well?
Post the code that doesn't work, not the one that does.

Carl.

>
> I am using 5.0.4, but, the same happens in 5.0.5
>

 

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

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