Hi hoping someone can point me in the right direction here. I need to use a variable to get a class property.
echo($objClass->😎; would work but I need to do it with a var:-
$myVar = B;
echo($objClass->$myVar);
I've included a code example below in case I'm looking at this in the wrong way.
/*
test_Products table
ProductID FeeID
1 2
2 3
--------------------
*/
class Product{
public $ProductID;
public $FeeID;
public function getProduct(){
// $rs = SELECT ProductID, FeeID, FROM test_Products WHERE ProductID = $this->ProductID;
if($rs->recordCount == 1){
$this->ProductID = $rs('ProductID');
$this->FeeID = $rs('FeeID');
return true;
}else{
return false;
}
}
}
$objProduct = new Product;
$objProduct->ProductID = 1;
$objProduct->getProduct();
/*
// We have the following vars are populated as expected:-
echo($objProduct->ProductID); // = 1
echo($objProduct->FeeID); // = 2
*/
/*
test_Fees table
FeeID A B C
1 20 10 15
2 30 20 10
--------------------
*/
class Fees{
public $FeeID;
public $A;
public $B;
public $C;
public function getFee(){
// $rs = SELECT A, B, C FROM test_Fees WHERE FeeID = $this->FeeID;
if($rs->recordCount == 1){
$this->A = $rs('A');
$this->B = $rs('B');
$this->C = $rs('C');
return true;
}else{
return false;
}
}
}
$objFees = new Fees;
$objFees->FeeID = $objProduct->FeeID; // = 2
$objFees->getFee();
/*
// The following vars are populated as expected:-
echo($objCodes->A); // = 30
echo($objCodes->B); // = 20
echo($objCodes->C); // = 10
*/
I'm pulling data from another class and have the following variable:-
echo($objZones->Zone); // = B
I need to use that variable to select which fee to return eg.
//echo('Cost: '.$objFees->$objZones->Zone); // this needs to = 20 ie $objFees->B