【发布时间】:2011-10-11 14:49:46
【问题描述】:
我尝试了网上所有可用的技巧,但不知道为什么,我无法访问该变量.. 这是包含私有变量的类的 sn-p:
class PANASONIC_PRICESHEET {
public $models = array();
public $options = array();
public $accessories = array();
private $identifier = '';
private $name = '';
private $currency1 = '€';
private $currency2 = '£';
/**
*
*/
public function __construct($name1 = 'unnamed', $identifier1 = '') {
$this->name = $name1;
$this->identifier = $identifier1;
}
public function getIdentifier() {
return $this->identifier;
}
/**
*
*/
public function getName($withIdentifier = false) {
if ($withIdentifier) {
return $this->name . " - " . $this->identifier;
} else {
return $this->name;
}
}
}
这是我访问它的方式:
$thisName = $pricesheet->getName();
$thisIdentifier = $pricesheet->getIdentifier();
我收到了这个错误:
Fatal error: Cannot access private property PANASONIC_PRICESHEET::$name in
C:\AppServ\www\dashboard\sites\all\modules\_custom\pricing_system\pricing_system.inc
on line 316
如何解决这个问题?我不能将字段设为 PUBLIC,它根本不是一个选项。请有任何建议。
编辑 - 1
问题已解决: 我想打电话给 $_pricesheet->getName(); 非常感谢您的建议。
【问题讨论】:
-
你确定这是所有导致错误的代码吗?
-
@Shef 所说的 - 这真的是导致错误的代码吗?
-
第 316 行,是您为访问它而设置的两个之一吗?还是课堂上的其中一条?因为那里肯定没有 316 行。
-
是的,这是我访问对象的代码。
标签: php drupal private fatal-error