RE: [SMARTY-DEV] object registration committed

From: Date: Fri, 24 Jan 2003 02:59:30 +0000
Subject: RE: [SMARTY-DEV] object registration committed
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-612@lists.php.net to get a copy of this message
Since a template consumer already needs to know which variables "have" methods and which don't, I think the explicitness of "->" will work better in the long run for method calls. How about allowing "." or "->" for property access, but requiring "->" for methods? Gary >-----Original Message----- >From: Monte Ohrt [mailto:monte@ispi.net] >Sent: Thursday, January 23, 2003 5:44 PM >To: Smarty Dev >Subject: [SMARTY-DEV] object registration committed > > >Support for object registration has been committed to CVS. > >I'm wondering which syntax would be best, "." or "->": > >{foo.bar} >{foo->bar} > >{foo.bar p1="foo"} >{foo->bar p1="foo"} > >The first is shorter and an existing syntax, the second is more >consistant with the longer object syntax and is distinct, possibly >avoiding future syntax collisions. So which is better, existing syntax >or distinct, more consistant syntax? > >as of now (in CVS) it is foo.bar but easily changed. > >Monte > >On Thu, 2003-01-23 at 14:50, Monte Ohrt wrote: >> OK so here's a proposal how object registration could work. >> >> First off, having to register each method is kind of >tedious. Typically >> you would want to register an entire object, but optionally limit the >> methods/properties that can be accessed. >> >> With that in mind, I'd like to try this template syntax: >> >> {foo.bar p1="blah" p2="blah"} >> >> Where foo is the object, and bar is the method. This gives a >syntactical >> distinction between template functions and objects, thus >allowing access >> to arbitrary methods within an object. This will also make parsing >> easier. >> >> Since functions and objects look and work differently, separate API >> calls should probably be used. Registering an object could >work like so: >> >> $smarty->register_object('foo', $objfoo); >> $smarty->register_object('foo', $objfoo, >> array('meth1','meth2')); >> $smarty->register_object('foo', $objfoo, null, true); >> >> * Objects are always registered by reference. >> * The second example limits access to the methods "meth1" >and "meth2". >> Parameters are passed much like template functions, where an array is >> passed as argument 1, and the Smarty object is passed as argument 2. >> * The third example registers the object such that >parameters are passed >> in the traditional sense, one var per argument. >> * Security settings are honored for private method access. >> * Special parameter "assign" will assign the output instead of >> displayed. >> >> As far as method vs. property, maybe we go with the idea >that a method >> takes precedence over a property of the same name? Otherwise >we have to >> make a syntactical distiction like {foo->bar} for properties. >> >> Monte > > > >-- >Smarty Development Mailing List (http://smarty.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > >

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