Re: [SMARTY-DEV] Re: object support

From: Date: Tue, 14 Jan 2003 15:05:33 +0000
Subject: Re: [SMARTY-DEV] Re: object support
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-536@lists.php.net to get a copy of this message
What I'd like to do is figure out a way to support objects without adding new syntax to the templates. We already support access to properties like this: {$foo->bar} But the more I look at it, the more I don't like it. It's adding a new syntax to the template language, and my gut feeling is this will cause more and more trouble. Let's figure out how to handle objects with what we have. With this goal in mind, Bharat's original idea is looking more appealing, use the same syntax as a template function. This should work the same regardless of PHP's OO future. Example: {themeFoo p1="foo" p2="bar"} would call $theme->foo("foo","bar"); or maybe $mystuff->theme->foo("foo", "bar"); basically whatever its registered it to point to. There is no visual distinction whether "themeFoo" is a function or an object, so the engine would need to decipher that. So then how do we handle these? Let's say we register it: $smarty->register_object('themeFoo', $theme, 'foo'); concerns: *) have to register every accessible method and property separately? It would be nice to register each object once somehow. I suppose you could do it in one go: $smarty->register_object( array('themeFoo','themeBar','themeBlah'), $theme, array('foo','bar','blah')); *) cannot have registered functions and registered objects of the same name Not a big deal? *) should registered objects be accessible from assigned vars? probably not (see next point) *) cannot have arrays of objects Maybe Smarty won't support arrays of objects natively, but if you _really_ need them, you can go ahead and assign the objects and get to them with a custom function (just like you can do now): {object name="foo->bar" p1="foo" p2="bar"} Of course we could just leave everything the way it is, and you just write custom functions as wrappers to handle objects. This is one extra step, but we could supply instructions in the manual how to do so. Also, your function can do anything you want: access assigned objects, unassigned objects, loop nested objects, etc. Monte On Tue, 2003-01-14 at 04:32, Nichlas Löfdahl wrote: > Greetings! > > Is there a hurry to implement object support in smarty-templates? > > My suggestion is that we wait (or at least limit) object-support in > templates until PHP5 with ZE2 is released. Right now PHP4 is semi-OO and I > think it'll be easier to define an object model when we know the future > OO-handling of PHP. > > /Nichlas > > > ----- Original Message ----- > From: "Monte Ohrt" <monte@ispi.net> > To: "Bharat Mediratta" <bharat@menalto.com> > Cc: "André Rabold" <arabold@nero.com>; "Smarty Dev" > <smarty-dev@lists.php.net> > Sent: Monday, January 13, 2003 11:27 PM > Subject: Re: [SMARTY-DEV] Re: object support > > > > ... and there's an issue with nested objects. support that? > > > > {$foo->bar->blah} > > > > {foo->bar->blah} > > > > If that is OK, then what about method access, that can only be set on > > the root object? > > > > Monte > > > > On Mon, 2003-01-13 at 14:22, Monte Ohrt wrote: > > > Another idea for object access syntax. > > > > > > We already support this syntax to access properties of objects: > > > > > > {$foo->bar} > > > > > > So why not access methods like this? > > > > > > {foo->bar p1="p1" p2="p2"} > > > > > > It is better than the {object ...} syntax, and still keeps a distinction > > > between functions and objects, all without conflicting what "foo.bar" > > > means. Also, it should be perfectly legal to have a registered function > > > and registered object of the same name, and this will work. > > > > > > This does break a little backward compatability since objects must now > > > be registered instead of assigned. But is there really a good reason or > > > advantage of having objects mixed with assigned variables? > > > > > > > > > Monte > > -- > > Monte Ohrt <monte@ispi.net> > > > > > > -- > > Smarty Development Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php -- Monte Ohrt <monte@ispi.net>

« previous php.smarty.dev (#536) next »