T_PAAMAYIM_NEKUDOTAYIM 听起来确实很异国情调,但对我来说绝对是胡说八道。我将其全部追溯到这行代码:
<?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 对象。这是课程:
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;
}
}
不知道为什么这不起作用/错误意味着什么......
T_PAAMAYIM_NEKUDOTAYIM 是 PHP 使用的双冒号范围解析 - ::
快速浏览一下你的代码,我认为这一行:
return $cnf::getConfig($key);
应该
return $cnf->getConfig($key);
第一种是静态调用方法的方法 - 如果 $cnf 包含也是有效类的字符串,则此代码将有效。 -> 语法用于调用类/对象实例上的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)