Page 1 of 1
arrays of objects and methods.
Posted: Sat Jul 06, 2002 11:41 pm
by untouchable
Code: Select all
<?
class testClass
{
var $a;
function printa()
{
echo $this->a;
}
}
$objї10] = new testClass;
$objї0]->a = 4;
$objї0]->printa();
?>
this does not work. at all. I'm not sure why but it sure as hell is frusturating.
the method printa will go as undefined but if you wish to do the following
or any form of echo, there is no problem. why does this happen, am i missing something?
Re: arrays of objects and methods.
Posted: Sat Jul 06, 2002 11:49 pm
by protokol
untouchable wrote:Code: Select all
<?
class testClass
{
var $a;
function printa()
{
echo $this->a;
}
}
$objї10] = new testClass;
$objї0]->a = 4;
$objї0]->printa();
?>
this does not work. at all. I'm not sure why but it sure as hell is frusturating.
the method printa will go as undefined but if you wish to do the following
or any form of echo, there is no problem. why does this happen, am i missing something?
The line $obj[10] = new testClass; means that you are instantiating an instance of the testClass and placing it into index 10 in the $obj array. So, when you do $obj[0]->whatever, it's not going to work because you did not specify an instance of the class in index 0 of $obj.
Make $obj[10] be $obj[0] and you'll see that your next lines will work.
Posted: Sun Jul 07, 2002 12:02 am
by untouchable
so how is it that i can print properties but not call methods?
Posted: Sun Jul 07, 2002 12:55 am
by volka
You're not printing a property but trying to set one. You should take a look into the error.log of your server
