【发布时间】:2011-01-12 15:17:14
【问题描述】:
我需要在运行时设置对象变量,它正在工作,但是 PHP 会返回我:
从空值创建默认对象 (/sct/fw FW_List.class.php:1142)
function initTemplates(&$object, $tpl_names)
{
global $FW_LIST_CONFIGURATION;
$is_custom = array();
foreach($tpl_names as $tpl_type) {
$object->$tpl_type = new template();
$object->$tpl_type->setTemplateText($FW_LIST_CONFIGURATION["templates"][$tpl_type]);
// place the defauts template values
$object->$tpl_type->setPlace( $FW_LIST_CONFIGURATION["css"][$tpl_type]);
}
return $is_custom;
}
ps。我不能使用$object = new stdClass,因为$object 是一个指针。
【问题讨论】:
-
1. PHP 不支持指针,那么
$object怎么可能是指针呢? 2. 由于PHP5默认所有对象都是通过引用传递的,所以你应该省略&。 3. 你使用了未定义的变量$stdObj和$$FW_LIST_CONFIGURATION。 -
对不起,我的代码是这样的:$object->$tpl_type 所以我写到这里,我错过了提问的时间:\
-
我编辑了问题,将原始函数放在我的代码中。
-
错误是这一行:$object->$tpl_type = new template();帮助!
标签: php object default stdclass