Array of instances not working...

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

Post Reply
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Array of instances not working...

Post 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...
Last edited by harrisonad on Thu Mar 17, 2005 11:15 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you misspelled 'array'.
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

it should print out 4
Post Reply