SORU
27 Aralık 2009, Pazar


Bu ne anlama geliyor? &; Ayrıştırma hatası":, T_PAAMAYİM_NEKUDOTAYİM" sözdizimi hatası, beklenmedik;

T_PAAMAYİM_NEKUDOTAYİM gerçekten ilginç, ama kesinlikle bana tamamen saçma geliyor. Hepsini bu kod satırları takip ettim:

<?php
Class Context {
    protected $config;

    public function getConfig($key) { // Here's the problem somewhere...
    $cnf = $this->config;
    return $cnf::getConfig($key);
    }

    function __construct() {
    $this->config = new Config();
    }
}
?>

Kurucu Config bir nesne yaratıyorum. İşte sınıf:

final class Config {
    private static $instance = NULL;
    private static $config;

    public static function getConfig($key) {
    return self::$config[$key];
    }

    public static function getInstance() {
    if (!self::$instance) {
        self::$instance = new Config();
    }
    return self::$instance;
    }

    private function __construct() {
    // include configuration file
    include __ROOT_INCLUDE_PATH . '/sys/config/config.php'; // defines a $config array
    $this->config = $config;
    }
}

Bu çalışmıyor neden hiçbir fikrim hata ne demek/...

CEVAP
27 Aralık 2009, Pazar


T_PAAMAYİM_NEKUDOTAYİM çift kolon kapsam çözünürlük PHP kullanır thingy - ::

Kodunuzu hızlı bir bakış, bu hat bence

return $cnf::getConfig($key);

olmalıdır

return $cnf->getConfig($key);

İlk statik olarak bu kod eğer $cümlesi de geçerli bir sınıf bir dize içeriyorsa geçerli olacak bir yöntem çağrısı için bir yoldur. ->sözdizimi sınıf/nesnesinin bir örneği üzerinde bir yöntemi çağırmak için.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:
Php

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Dopelives

    Dopelives

    30 Temmuz 2009
  • esnathesinger

    esnathesinge

    6 NİSAN 2009
  • mahalodotcom

    mahalodotcom

    8 HAZİRAN 2007