• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Notice: Undefined property: stdClass:: ...
PostPosted: Mon May 13, 2019 5:52 pm 
Offline
Forum Members
Forum Members

Joined: Thu Jun 19, 2008 5:24 pm
Posts: 44
You might come across this issue now and then.
For example in the FormBuilder module:
Code:
Notice: Undefined property: stdClass::$op in ... tmp\templates_c\...

The first solution that comes to the most peoples mind is to check the exsitence of that mentioned property in the template before accessing it.
The funny part is that this issue is caused because you ARE checking for the existance of that property.
The problem is within Smarty
To be more precise it's the {section} plugin.
{section} - similar to {foreach} - does someting more than just to loop over a given structure. And by that is uses parts of {foreach}. The result of these parts are used as index in a more complex array-like structure. {section} does not validate that result. And if "null" is returned by the {foreach} compiler part this will result in an invalid index.
Example of FormBuilder:
Code:
$_prefixVariable1=$_smarty_tpl->tpl_vars['entry']->value->input[(isset($_smarty_tpl->tpl_vars['__smarty_section_numloop']->value['index']) ? $_smarty_tpl->tpl_vars['__smarty_section_numloop']->value['index'] : null)]->op;

This code might result in
Code:
... $some_array[null]->op;

which obviously is wrong.

The solution is either to modify your templates to check more often for the existence of properties or completely avoid {section} and use {foreach} instead.

Again the example of FormBuilder. In the original template for inputs that consist of multiple parts (e.g. a group of checkboxes) this is used :
Code:
{section name=numloop loop=$entry->input}
   {if $entry->label_parts == 1}
      <div>{$entry->input[numloop]->input}&nbsp;{$entry->input[numloop]->name}</div>
   {else}
      {$entry->input[numloop]->input}
   {/if}
   {if isset($entry->input[numloop]->op) && $entry->input[numloop]->op}{$entry->input[numloop]->op}{/if}
{/section}

Solution #1 - check more often for the existence of properties.
Replace this line right before {/section}:
Code:
{if isset($entry->input[numloop]->op) && $entry->input[numloop]->op}{$entry->input[numloop]->op}{/if}

With these lines.
Code:
{if isset($entry->input[numloop])}
   {$___tmp=$entry->input[numloop]}
   {if isset($___tmp->op) && $___tmp->op}
      {$___tmp->op}
   {/if}
{/if}

Solution #2 - {foreach}:
Code:
{foreach from=$entry->input item=entry_input}
   {if $entry->label_parts == 1}
      <div>{$entry_input->input}&nbsp;{$entry_input->name}</div>
   {else}
      {$entry_input->input}
   {/if}
   {if isset($entry_input->op)}{$entry_input->op}{/if}
{/foreach}

Cheers.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Hosting Nation - Managed CMSMS Hosting