1

I need to set the object variable at run time, it is working, but PHP returns me:

Creating default object from empty value (/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. i can't use $object = new stdClass, because $object is a pointer.

4
  • 1. PHP doesn't support pointers so how $object could be a pointer? 2. Since PHP5 all objects are by default passed by reference, so you should omit &. 3. You're using undefined variables $stdObj and $$FW_LIST_CONFIGURATION.
    – Crozin
    Commented Jan 12, 2011 at 15:28
  • sorry, my code looks like this: $object->$tpl_type and so I wrote here, I missed the time to ask the question :\
    – NandoBas
    Commented Jan 12, 2011 at 15:47
  • I edited the question, putting the original function, the way it is in my code.
    – NandoBas
    Commented Jan 12, 2011 at 15:55
  • the error is this line: $object->$tpl_type = new template(); help!
    – NandoBas
    Commented Jan 12, 2011 at 16:06

1 Answer 1

1

resolved, the secret was to use Array;

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.