objects: one more approach

From: Date: Wed, 15 Jan 2003 16:15:45 +0000
Subject: objects: one more approach
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-539@lists.php.net to get a copy of this message
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. 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. 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'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); 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. Monte

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