new object support in cvs
| From: | Monte Ohrt | Date: | Sat, 18 Jan 2003 00:19:25 +0000 |
| Subject: | new object support in cvs | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-563@lists.php.net to get a copy of this message | ||
The latest CVS commit supports the new object access methods discussed
in the dev mailing list. There is no new template syntax necessesary, a
very good thing for the longevity of Smarty. This is not tested very
thorougly, but I wanted to get it out there for you developers to play
with.
All objects must be assigned just as template variables are assigned.
There is (not yet) any object registration. Private method access is
revoked when security is enabled.
example: accessing an assigned object property:
{$foo.bar}
The compiler figures out if "foo" is an array or object by examining the
currently assigned value at compile time. That means if you change an
assigned value from an array to an object after compiling (likely to
never happen unless you have a delusional desire to keep things
confusing), you must recompile.
example: accessing an assigned object method:
{$foo.bar}
Same syntax. If a method of this name exists, it is treated as a method.
otherwise, it is treated as a property.
example: accessing a method with parameters
{$foo.bar p1="foo" p2=$bar}
This will call the method as such (by default):
$foo->bar(array("p1" => "foo", "p2" => "bar"),
$this);
If you want to pass parameters the traditional way, you must use the
reserved parameter "wrapper":
{$foo.bar p1="foo" p2=$bar wrapper=true}
this will call the object like so:
$foo->bar("foo",$bar")
You can change the default wrapper behavior by adjusting the smarty var
$this->_object_wrapper. I'm not sure if it should be a public or private
value, I set it to private for now.
If you want the output of the object call assigned instead of displayed,
use the assign parameter:
{$foo.bar p1="foo" assign="output"}
With this new object support, the engine syntax now allows parameters to
be passed on a variable call:
{$foo bar="blah"}
For the meantime this is accepted syntax but just ignored. I did notice
that assign will work (wierd side effect):
{$foo assign="blah"}
that is the same as doing:
{assign var="blah" value=$foo}
The syntax for accessing object properties is still accepted, but
probably will be deprecated:
{$foo->bar}
use this instead:
{$foo.bar}
You can have nested objects and such, works fine in my tests:
{$foo.bar.blah.hey p1-"foo"}
{$foo[sec].bar p2="blah"}
The engine will figure out what is arrays and what is objects.
Monte