从空值创建默认对象

时间:2011-01-12 15:17:14

标签: php object default stdclass

我需要在运行时设置对象变量,它正在运行,但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 个答案:

答案 0 :(得分:1)

解决了,秘密就是使用Array;

$object->test[$tpl_type] =  new template();
$object->$tpl_type = $object->test[$tpl_type];
$object->$tpl_type->setTemplateText($FW_LIST_CONFIGURATION["templates"][$tpl_type]);
相关问题