是的...我正在创建一个类,我想使用预定义(即const)数组作为私有类成员但是php没有加载数组,即当我在构造函数中尝试array_flip时它告诉$ fieldnamemap为空
class RETS_translate {
// hold the datebase connection that gets passed in constructor
private $dbConn;
// IMPORTANT! this is the bridge between old system and new system...handle with care
private $fieldNameMap = array(
"StreetNumber" => "street_number",
"StreetName" => "street_name",
"StreetSuffix" => "street_suffix",
"City" => "city",
"StateOrProvince" => "state_province",
"PostalCode" => "postal_code",
"YearBuilt" => "year_built",
"PropertyType" => "property_type",
"SqFtLivingArea" => "square_footage",
"Bedrooms" => "bedrooms" ,
"BathsTotal" => "bathrooms",
"PoolPresent" => "pool",
"WaterFrontPresent" => "waterfront",
"WaterFrontageDesc" => "water_type",
"Parking" => "parking",
"SplitYN" => "Spli,Floorplan",
"HomeOwnersAssocYN" => "hoa",
"AssociationFee" => "hoa_dues",
"Construction" => "construction",
"ExteriorFinish" => "exterior_finish",
"Roof" => "roof_type",
"FireplacesYN" => "fireplace",
"County" => "county",
"Gates" => "gated_community",
"FurnishingstoStay" => "furnishing",
"HomeWarrantyYN" => "home_warranty",
"TaxYear" => "tax_year",
"TaxAmount" => "tax_amount",
"Community55YN" => "over_55",
"ShortSaleYN" => "Short Sale/Bank Owned",
"DwellingStyle" => "home_style",
"PublicRemarks" => "remarks",
"ExteriorFeatures" => "exterior_features",
"InteriorFeatures" => "interior_features",
"PoolDescription" => "pool_features",
"Utilities" => "utilities",
"EquipmentAndAppliances" => "equipment_appliances",
"Floor" => "floor",
"Subdivision" => "subdivision",
"DwellingView" => "home_view",
"AdditionalRooms" => "additional_rooms",
);
private $fieldNameMapFlip;
function __construct($inDb=NULL) {
// store db connection for later use...
$this->dbConn = $db;
$fieldNameMapFlip = array_flip($fieldNameMap);
} // end constructor
}
答案 0 :(得分:0)
由于它是该类的一部分,因此您需要使用$this
访问该数组。改变
$fieldNameMapFlip = array_flip($fieldNameMap);
到
$fieldNameMapFlip = array_flip($this->fieldNameMap);
答案 1 :(得分:0)
$ fieldNameMapFlip = array_flip($ this-> fieldNameMap);