0

是的...我正在创建一个类,我想在其中使用预定义(即 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 

    }
4

2 回答 2

1

由于它是类的一部分,因此您需要使用$this. 改变

$fieldNameMapFlip = array_flip($fieldNameMap);

$fieldNameMapFlip = array_flip($this->fieldNameMap);
于 2013-09-12T16:45:58.467 回答
0

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

于 2013-09-12T16:45:59.710 回答