Posted by Mike Zhang on 11/04/01 11:55
I have the following class shop and function. makelist
makelist() function is going to generate the dummy data for testing.
At the end when displaying the id and shopname I only get the shopname for
both $shoplist[$i]->getID() and $shoplist[$i]->getName() why is that?
Class Shop{
var mID;
var mName;
function setID( $id ){
$this->$mID=$id;
}
function getID(){
return $this->$mID;
}
function setName( $name ){
$this->$mName=$name;
}
function getName(){
return $this->$mName;
}
}
function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}
$shoplist = makelist();
for( $j=0;$j<10;$j++){
echo "ID: " . $shoplist[$i]->getID()."Name: ".$shoplist[$i]->getName();
}
}
Navigation:
[Reply to this message]
|