Re: [SMARTY-DEV] Re: object support (more thoughts)
| From: | Rob Ellis | Date: | Mon, 13 Jan 2003 23:50:44 +0000 |
| Subject: | Re: [SMARTY-DEV] Re: object support (more thoughts) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-532@lists.php.net to get a copy of this message | ||
On Mon, Jan 13, 2003 at 05:14:21PM -0600, Monte Ohrt wrote:
> If we force registration of objects, then you have to access an object like this:
>
> {$foo->bar}
> {foo->bar}
>
> This means you cannot have an array of objects to access in a section loop, such as:
>
> {section name=bar loop=$foo}
> {$foo[bar]->blah}
> {/section}
>
> If we need to support that, then it would mean objects must be assigned instead of registered.
> If they are assigned, then individual control over method access isn't really feasible,
> we would have to allow access to all methods exluding private ones. All or none. This also
> complicates the syntax, we are almost back to square one {$foo->bar()}
>
> So decisions:
>
> 1) register all objects, and can only access directly:
>
> {$foo->bar} <-- property
> {foo->bar p1="foo"} <-- method
>
> PROS: * syntax kept to a bare minimum
> CONS: * not as flexible can't assign arrays of objects
>
>
> 2) assign all objects, and allow access to all methods excluding private ones:
>
> {$foo->bar}
> {$foo.bar->blah}
> {$foo[bar].foo->blah}
> {foo.bar[foo]->foo p1="foo" p2="bar"}
>
> PROS: * can assign objects or arrays of objects, more flexible
> CONS: * syntax is more complex
> * can't control individual method access
>
>
> I'm really leaning toward option #1. Is there a practical use for assigning
> arrays of objects?
How about
{$foo.bar} and
{$foo.bar p1="foo"}
and sort out the ambiguity by checking $foo.bar constructs with
is_object($foo) and method_exists($foo, 'bar') ?
Object methods for output are often var-like anyway...?
e.g. {$person.print_email p1="uucp"}
Then you could treat an array of objects as a regular array:
{foreach item="person" from=$people}
Name: {$person.name}<br />
Email: {$person.print_email p1="uucp"}<br />
etc.
{/foreach}
- Rob
--
Rob Ellis <rob@web.ca>
System Administrator, Web Networks