Re: [SMARTY-DEV] objects: one more approach
| From: | M Mohr | Date: | Wed, 15 Jan 2003 16:54:45 +0000 |
| Subject: | Re: [SMARTY-DEV] objects: one more approach | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-543@lists.php.net to get a copy of this message | ||
Hello,
On Wed, Jan 15, 2003 at 10:15:45AM -0600, Monte Ohrt wrote:
> How about this.
>
> You assign objects just like variables. Let's say $foo is an assigned
> object.
>
> At first I thought about this syntax:
>
> {$foo.bar} <-- property
> {$foo.bar p1="foo" p2=$bar} <-- method
>
> But, this isn't simple because at compile time the parser doesn't know
> if $foo.bar is an array or an object, they require different syntax in
> the compiled template. I could either pass this to a function and figure
> it out at runtime (extra step), or use a separate syntax for objects:
>
> {$foo->bar} <-- property
> {$foo->bar p1="foo" p2=$bar} <-- method
>
> ok, now we know at runtime if it is an object, and how to compile it.
^^^^^^^ you mean compiletime here, right?
> Also with this syntax of passing parameters it is nothing new for the
> parser. The one problem I see is no distiction between a property and a
> method with no args. Ideas? Maybe we don't worry about it. If the method
> exists, use that. Otherwise use the property.
this sounds great to me for not registered objects.
> If an object is not registered, you have access to all methods and
> properties except private ones. If registered, then restricted access to
> registered methods (but leave access to properties, or register them
> too?)
i think it would be enough to register the methods and not the
properties. just to save the overhead of having to check the
accessibility of each property before accessing it. but this is a
performance concern, which should be left out in the design-phase, right?
> I'm also wondering how the object parameters should be handled. example:
>
> {$foo->bar p1="foo" p2=$bar}
>
> 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.
maybe:
$smarty->register_object('foo', array('bar_flat'),
array('bar_smarty'))
with
class Foo {
function bar_flat($foo, $bar) ...
function bar_smarty($params, &$smarty) ...
}
> Notice the second one is much like registered functions, all parameters
> are passed as an array in the first argument, and the smarty object
> passed in the second. Maybe we should do this with objects too.
additionaly i would tend to not to register objects, but classes (via
the classname). all (assigned) objects that belong to the registered
class would have the specified accessibilty it their methods (and
properties maybe).
why would one want to allow accessing $obj1->foo but not $obj2->foo if
they do the same on slightly different data?
if i wanted this, i would put the check inside foo() but not in the
setup of my smarty-object.
just MHO
messju
> Monte