Page 1 of 1

Array of instances not working...

Posted: Thu Mar 17, 2005 11:08 pm
by harrisonad

Code: Select all

Class A{
var $value;
function A($val){
$this->value = $val;
}
function getValue(){ 
return $this->value;
}
}

Class B{
var $aray = array();
function B(){
$this->aray[] = new A(4);
$this->aray[] = new A(2);
$this->aray[] = new A(7);
}
function getArray(){
return $this->aray;
}
}

$obj = new B();
$myaray = $obj->getArray();
echo $myaray[0]->getValue(); // this will not recognise 'getValue()' as method
Can you please tell me why this happened.

Thanks in advance...

Posted: Thu Mar 17, 2005 11:12 pm
by feyd
you misspelled 'array'.

Posted: Thu Mar 17, 2005 11:17 pm
by hongco
it should print out 4