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

Posted by www.douglassdavis.com on 10/11/05 19:22

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.

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

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