2013-09-12 5 views
0

yes ... im создание класса, где я хочу использовать предопределенный массив (т.е. const) как частный член класса, но php не загружает массив, то есть, когда я пытаюсь array_flip в конструкторе, его сообщение $ fieldnamemap пуст.инициализация частного массива в классе в php

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

Поскольку это часть класса вы должны получить доступ к массиву, используя $this. Изменение

$fieldNameMapFlip = array_flip($fieldNameMap); 

в

$fieldNameMapFlip = array_flip($this->fieldNameMap); 
+0

да..lol конечно я действительно спасибо. Приходите на фон C/C++, я, кажется, всегда забываю об этом – menriquez

+0

@menriquez - Ха-ха не беспокоится. – Aust

0

$ fieldNameMapFlip = array_flip ($ this-> fieldNameMap);

Смежные вопросы