这是什么意思? “解析错误:语法错误,意外的T_PAAMAYIM_NEKUDOTAYIM"; [英] What does this mean? "Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM"
问题描述
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();
}
}
?>
在构造函数中,我创建一个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...
推荐答案
T_PAAMAYIM_NEKUDOTAYIM是PHP使用的双冒号范围解析-::
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);
应该是
return $cnf->getConfig($key);
第一种是静态调用方法的方法-如果$ cnf包含一个也是有效类的字符串,则此代码将有效. ->语法用于在类/对象的实例上调用方法.
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.
这篇关于这是什么意思? “解析错误:语法错误,意外的T_PAAMAYIM_NEKUDOTAYIM";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!