Re: [SMARTY-DEV] objects: one more approach
| From: | Monte Ohrt | Date: | Wed, 15 Jan 2003 17:50:18 +0000 |
| Subject: | Re: [SMARTY-DEV] objects: one more approach | ||
| References: | 1 2 3 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-549@lists.php.net to get a copy of this message | ||
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>