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

Problem with nested objects

 
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
c77m
Smarty n00b


Joined: 09 Jul 2003
Posts: 2

PostPosted: Wed Jul 09, 2003 12:25 pm    Post subject: Problem with nested objects Reply with quote

I am trying to implement some pages that make use of nested objects, ie:
Code:

class Obj1 () {

  function Obj1() {
    $this->attribute1 = new Obj2();
  }

  function obj2() {
    return $this->attribute1();
  }
}

$obj1 = new Obj1();
$smarty->assign_by_ref("obj1");


I am having trouble referring to the nested object in my templates. Addressing attributes DOES work:

Code:
{$obj1->attribute1->attribute2}


Addressing object functions does not:

Code:
{$obj1->obj2()->attribute2}


I can't seem to find any examples. Can someone tell me what I am doing wrong?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 09, 2003 4:02 pm    Post subject: Reply with quote

Hi.

Quote:
Addressing object functions does not:

Code:
{$obj1->obj2()->attribute2}


Dereferencing functions like this also does not work in PHP4, by-the-way, which is *probably* why it does not work in Smarty.


Last edited by boots on Wed Jul 09, 2003 9:33 pm; edited 1 time in total
Back to top
View user's profile Send private message
c77m
Smarty n00b


Joined: 09 Jul 2003
Posts: 2

PostPosted: Wed Jul 09, 2003 8:17 pm    Post subject: Reply with quote

Well howabout that... that could be the problem indeed. Smile I ran into this while I was trying to clean up my code (by addressing object funtions instead of properties.) Time for a new approach.

thanks again..
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 09, 2003 9:36 pm    Post subject: Reply with quote

I forgot to mention that as per PHP4, you can still do an intermediate assignment to mimic the behaviour you desire--its just not as clean and possibly not as fast (especially if you don't pass by reference):

{assign var=temp value=$obj1->obj2()}
{$test->attribute2}
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