object registration committed

From: Date: Thu, 23 Jan 2003 23:43:59 +0000
Subject: object registration committed
References: 1 2 3 4 5  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-609@lists.php.net to get a copy of this message
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

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