Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

php - What does this mean? "Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM"

T_PAAMAYIM_NEKUDOTAYIM sounds really exotic, but most certainly absolutely nonsense to me. I traced it all down to this lines of code:

<?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();
    }
}
?>

In the constructor I create a Config object. Here's the class:

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;
    }
}

No idea why this doesnt work / what the error means...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

T_PAAMAYIM_NEKUDOTAYIM is the double colon scope resolution thingy PHP uses - ::

Quick glance at your code, I think this line:

return $cnf::getConfig($key);

should be

return $cnf->getConfig($key);

The first is the way to call a method statically - this code would be valid if $cnf contained a string that was also a valid class. The -> syntax is for calling a method on an instance of a class/object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...