PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Aug 19, 2006 1:07 pm
Any reason why this wouldn't work?
Code: Select all
class frustrated
{
const MY_CONSTANT = 3;
function __construct()
{
$test = "ya";
$foo = foo::getInstance();
}
function test_vars()
{
echo MY_CONSTANT;
echo $this->test;
echo $this->foo;
}
}
I am getting undefined variable notices for all 3 of the echo's.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 19, 2006 1:11 pm
Code: Select all
class frustrated
{
const MY_CONSTANT = 3;
function __construct()
{
$this->test = "ya";
$this->foo = foo::getInstance();
}
function test_vars()
{
echo self::MY_CONSTANT;
echo $this->test;
echo $this->foo;
}
}
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat Aug 19, 2006 1:16 pm
Ok I feel dumb now. I originally had it like that and was getting undefined variable notices, but it was because I had a $ in front of them.