Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Recursion + undefined method stdClass::__set_state()

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
platinum_pt78
Smarty n00b


Joined: 20 Sep 2011
Posts: 1

PostPosted: Tue Sep 20, 2011 5:27 am    Post subject: Recursion + undefined method stdClass::__set_state() Reply with quote

Hi -

Just trying to upgrade from Smarty2 to Smarty3 and just stuck on this error now, I think it might be because the results are in object form rather than arrays... this works fine in smarty2 though.

here's the code (actually using an example from smarty, so it's easier to debug):

Code:
<ul id="aside">{function name="menurecursion" list=$dataset}
{foreach from=$list item=element}
{if !empty($element->children)}
<li id="{$element->id}">
    <div class="maincat"><a href="#">{$element->title}</a></div>
{else}<li>{$element->title}
{/if}
    {if !empty($element->children)}
        <ul>{menurecursion list=$element->children}</ul>
    {/if}
</li>
{/foreach}
{/function}


error:

Code:
Fatal error: Call to undefined method stdClass::__set_state()  .... line 24


here's an example of what is in the compiled template:

Code:
  'function' =>
  array (
    'menurecursion' =>
    array (
      'parameter' =>
      array (
        'list' =>
        array (
          0 =>
          stdClass::__set_state(array(
             'id' => '2',
             'category' => 'Pages',
             'datasetID' => '2',
             'parentID' => '0',
             'catURL' => '',
             'sortorder' => '4',
             'children' =>
            array (
              0 =>
              stdClass::__set_state(array(
                 'id' => '66',
                 'category' => 'Sections',
                 'datasetID' => '2',
                 'parentID' => '2',
                 'catURL' => NULL,
                 'sortorder' => '1',
                 'children' => NULL,
                 'data' =>
                array (.....



any help would be appreciated!
Back to top
View user's profile Send private message
ikund
Smarty Rookie


Joined: 22 Nov 2011
Posts: 9

PostPosted: Tue Nov 22, 2011 12:57 pm    Post subject: Reply with quote

I'm having exactly the same issue. For some reason Smarty tries to serialise "function" attributes, but this does not work very well with even slightly complex objects.

Any help would be very much appreciated!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Nov 22, 2011 4:57 pm    Post subject: Reply with quote

We did expect the default parameter values to be a scalar same as default PHP function parameters.

There is no need that the default parameter are variable because you can use the variable as parameter on the initial of the template function.
Back to top
View user's profile Send private message
dave101ua
Smarty n00b


Joined: 23 Jan 2014
Posts: 4

PostPosted: Fri Nov 25, 2016 3:48 pm    Post subject: Reply with quote

Hello everybody!
I have same problem, I read messages above but still don't get what I have to do in order to fix that.

I'm trying to move from Smarty 2 to 3
problem occurs only if I enable caching for that page, if I disable cache then all works fine.
So when cache enabled I get error like this:
Fatal error: Call to undefined method stdClass::__set_state() in ....

Compiled template where error happens is:

Code:
<div data-sticky="10">
                                    <?php echo insert_quickorderMenuLinks(array (
  'category' =>
  stdClass::__set_state(array(
     'category_id' => '4633',
     'site_type_id' => '17',
     'name' => 'Shop',
     'parent_category_id' => '4569',
  )),
  'shop_group_id' => '25',
),$_smarty_tpl);?>
                            </div>



can somebody tell me what is wrong here and how to fix ?
Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP