Re: [SMARTY] call to class/method -- function included

From: Date: Thu, 19 Dec 2002 12:46:05 +0000
Subject: Re: [SMARTY] call to class/method -- function included
References: 1 2 3  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6895@lists.php.net to get a copy of this message
On Thu, Dec 19, 2002 at 01:41:41PM +0100, M Mohr wrote: > On Thu, Dec 19, 2002 at 12:11:33PM +0100, akorthaus@web.de wrote: > > Hi Mark! > > > > I think this is exactly what I want to do, thank you very much. I only > > have to copy this file into the "plugins" folder and I can use it as > > described? > > > > regards, > > Andreas > > > > >Hmm.. my attachment didn't seem to make it to the list.. Oh well, here's > > >the source, for those interested. > > > > > >-mark > > > > > ><?php > > > > > >/* > > >* Smarty plugin > > >* ------------------------------------------------------------- > > >* Type: function > > >* Name: call > > >* Author: Mark Priatel (mpriatel@rogers.com) > > >* Input: obj = the object to call a method on > > >* method = the method to call > > >* arg1 .. arg4 (optional) = an argument for the method > > >* > > >* Examples: {call obj=$connection method='close'} > > >* {call obj=$connection method='open' arg1='localhost'} > > >* {call obj=$connection method='open' arg1='localhost' > > >* arg2='password' } > > >* > > >* ------------------------------------------------------------- > > >*/ > > >function smarty_function_call($params, &$smarty) > > >{ > > > > > > $o = $params['obj']; > > > if ( !isset($o) ){ > > > $smarty->trigger_error("function 'call' requires > > >argument 'obj'"); > > > return; > > > } > > > > > > $m = $params['method']; > > > if ( !isset($m) ){ > > > $smarty->trigger_error("function 'call' requires > > >argument 'method'"); > > > return; > > > } > > > > > > $i = 1; > > > $args = array(); > > > while( isset($params["arg$i"]) ){ > > > array_push($args,$params["arg$i"]); > > > $i++; > > > } > > > > > > switch( sizeof($args) ){ > > > case 0: return $o->$m(); > > > case 1: return $o->$m($args[0]); > > > case 2: return $o->$m($args[0],$args[1]); > > > case 3: return $o->$m($args[0],$args[1],$args[2]); > > > case 4: return $o->$m($args[0],$args[1],$args[2],$args[3]); > > what about "call_user_method_array($m, $o, $args);" ? > it is available since 4.0.5 (so widely supported) and handles an arbitrary > number of args. oops, and i see it is deprecated and should read: "call_user_func_array(array(&$o, $m), $args);" use whatever version you prefer :) > have fun > messju > > > > } > > > > > >} > > >?> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > Smarty General Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#6895) next »