Re: [SMARTY-DEV] objects: one more approach

From: Date: Thu, 16 Jan 2003 08:25:13 +0000
Subject: Re: [SMARTY-DEV] objects: one more approach
References: 1 2 3 4  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-551@lists.php.net to get a copy of this message
Hello, I tend to use the first syntax $foo->bar("foo", "bar"). You could register objects using $smarty->register_object('foo', array('bar','blah')); So we know the first argument of foo is"bar", the second is "blah" now both {$foo->bar bar="1" blah="2"} and {$foo->bar blah="2" bar="1"}work well. The method call is always $foo->bar("1","2"). Or am I wrong? If I first need to rewrite all objects or make a wrapper method for them why should I even use object support in Smarty? In this case I can make just normal Smarty Function Plugins. And please consider one thing: If you implement object access in Smarty you also need to implement objects for {if}. I still like the very first implementation {$foo->bar(1,2,3)} the best because it was the easiest to learn syntax for all semi-programmers. If you combine this syntax with the $smarty->register_object() thing it would be the most powerful solution and it would be a clear way. Object property support was already implemented in Smarty and I'm sure some / alot of people are already using it. So modifying the syntax wouldn't be too good. Once again: The next logical step would be {$foo->bar($a,$b,$c)} syntax for me. But I know you don't like it very much. * Syntax is common for all semi-programmers (to develop a template also needs some programming skills) * Class methods are often methods which return a value. There's a difference between returning a value like $foo->getBar() and a normal Smarty Plugin which is outputting something. To retrieve a method's return value using the above syntax you would need to to something like this: {capture name="bar"}{$foo->bar bar="1" blah="2"}{/capture} {myFunction foo=$bar} Using the {$foo->bar($a,$b)} syntax it would look like this {myFunction foo=$foo->bar($a,$b)} * You could also use set-Methods of objects which can get you in some trouble. But you this is not the problem of {$foo->bar($a,$b,$c)} but also if you use {$foo->bar bar=$a blah=$b}. So this is no real argument. bye, André "Monte Ohrt" <monte@ispi.net> schrieb im Newsbeitrag news:1042653018.2123.104.camel@lena.ispi.prv... > It looks like we have views from both sides of the fence :-) > > $foo->bar("foo","bar"); > > vs. > > $foo->bar(array('p1' => "foo", 'p2' => $bar), $this); > > for the latter: > > PROS: * order of args in template don't matter > * smarty object passed as parameter > * key names maintained > * complies with smarty function format > > CONS: * existing objects must be rewritten to smarty specs, or wrappered > > > I can see where it would be nice to use existing objects with > smarty without a lot of rework. Maybe we should figure out a way to > handle both. A smarty var that globally determines how they are parsed? > Or to handle each separately, have a special parameter: > > {$foo->bar p1="foo" p2="bar" wrapper=true} > > This would make the object compile as: > > $foo->bar("foo","bar"); > > > > > On Wed, 2003-01-15 at 11:33, Nick Charsley wrote: > > [..] > > > > which should happen? > > > > > > > > $foo->bar("foo", $bar); > > > > > > > > or > > > > > > > > $foo->bar(array('p1' => "foo", 'p2' => > > > > $bar), $this); > > > > > > i prefer the former, since it is the most flexible and existing > > > object-api can be used that way. it would be great if the second could > > > be registered as a special method also. > > > > > I too prefer the former, the main reason why is that most objects will have > > been written to accept arguments in this way so if I have my fully working > > and tested foo class I can just drop it into smarty and don't have to write > > a new 'smartyBar($array,$this)' method that unpicks the arguments and then > > calls $this->bar($p1,$p2). > > If I'm exposing a lot of methods then I'm not sure I've gained anything, and > > I've certainly lost the re-usability of my object. > > > > just my tupence worth > > > > Nick (c) > -- > Monte Ohrt <monte@ispi.net> >

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