Sınıf örnek değişkenler php null olma

0 Cevap

Ben Amacı bir veritabanından bazı yapılandırma verileri almak ve daha sonra kullanmak üzere saklamak için bu PHP sınıfı var:

class GSConfig {
  private $configurationData;
  private $repository;

  public function __construct($pRepository) {
    $this->repository = $pRepository;
    $this->configurationData = $this->InitializeConfiguration();
  }

  public function InitializeConfiguration() {
    $result = $this->repository->configLoadAll();
    if ( $result['data'] ) {
      $conf_array = $result['data'];
      foreach ( $conf_array as $row) {
        $code = strtolower($row ['code']);
        $value = strtolower($row ['value']);
        //if ($value == "true") $value = (bool)true;
        //if ($value == "false") $value = (bool)false;
        $this->configurationData[$code] = $value;
      }
    } else {
      $this->configurationData = null;
    }
    print_r($this->configurationData);
  }

  public function getConfigValue($key) {
    $key = strtolower($key);
    if ($this->configurationData != null) {
      if( isset($this->configurationData[$key])) {
        return $this->configurationData[$key];
      }
    } else if ($this->configurationData == null) {
      // If we reach this code, something went wrong
      // (TODO: throw Exception)
      echo "<p>Tick</p>";
    }
  }
}

InitializeConfiguration gets the data and stores it as an array in the $configurationData property. This is working as expected as shown by the output of the print_r function. However, after initializing, if i attempt to read any value from the $configurationData, i get Tick. Somehow the variable becomes null after the Initialization.

Çıkış gibi bir şey olurdu:

print_r output:
Array ( [show_cart] => true [order_mail] => order@shop.de [debug_mode] => true [branch_mode] => true [default_branch] => 1 [agb_file] => agb.txt [kat_order] => k_nr [show_rows] => 5 [product_order] => p_produktnr [cost_per_wu] => 0.66 [message_lang] => eng [free_shipping] => true [free_ship_amt] => 25 [special_price] => true [discounts] => true [cat_show_mode] => all [price_att] => ersatzpreis [mwst_att] => mehrwertsteuer [aktionsp_att] => aktionspreis [katalog_mode] => per_branch )
further output: 
Tick
Tick
...
Tick

Bu happenning neden herkes bilir? Btw, benim PHP version 5.3.1 olduğunu

0 Cevap