object problems

From: Date: Tue, 21 Jan 2003 16:04:46 +0000
Subject: object problems
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-566@lists.php.net to get a copy of this message
It seems the idea of using foo.bar for object syntax isn't working very well. Since objects can be assigned at runtime, there is no way to know at compile time how to compile foo.bar, either as an array or as an object. The overhead of figuring this out at runtime isn't going to be worth it, so it must be compiled correctly. If we are going to support objects in Smarty, it is either going to have to have its own syntax, or we limit the use of objects by having all objects registered, meaning they must exist before the template is executed (or your runtime functions/objects register new objects on-the-fly) options: 1) register all objects and methods: $smarty->register('myFoo', $my, 'foo'); {myFoo p1="blah" p2="blah"} PROS: * no new syntax, looks just like a template function call. CONS: * cannot have arrays of objects to loop over * cannot pass object as parameter to function * every method must be registered before hand * property access? 2) support new syntax for objects: {$foo->bar($foo, "bar", $blah[0].blah, nl2br($foo))} PROS: * mimics PHP native object syntax (?) * can pass object as parameter to function * can differentiate properties from methods CONS: * new template syntax introduced, now we pass parameters two different ways * may lead to new syntax problems, such as passing objects as parameters to objects We could go this route: {$foo->property} {$foo->method() p1="p1" p2="p2"} But is that much better than {$foo->bar("p1","p2")} The second one could be passed as a parameter, but not the first. But the first one does retain the parameter passing syntax. Any other thoughts/ideas, please do tell. I'd really like to figure out a way to use objects without new syntax or new style of passing parameters, but I don't know if that's feasible. Monte

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