Re: function -> action

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Aug 3, 2007, at 9:39 AM, Ken Tozier wrote:


On Aug 3, 2007, at 2:38 AM, Ralph Kutschera wrote:

Hallo!

I'm working on a project, where we distinguish between "functions" and "actions" in design, although in PHP both are implemented as functions.
Is there a chance that PHP can use the word "action" as "function"?

E.g.:
public function doSomething() { .... }
public action doSomethingElse() { ... }

... is actually the same but would help to see the design also in the code.

You could define a generic action function

function action($funcName, $funcArgs)
{
	return $funcName($funcArgs);
}

Actually, this might be better as it makes no assumptions about the function's argument list.

function action()
{
	$func		= func_get_arg(0);
	$expr		= func_get_args();
	$expr		= array_slice($expr, 1);
	$expr		= implode(', ', $expr);
	$expr		= $func.'('.$expr.');';
	
	return eval($expr);
}

You lose the ability to pass by reference but that might not be important for your script.


and use it on any function you want to use as an action function

function printColor($color) {
	echo 'color: '.$color.'<br>';
}

function printArea($width, $height) {
	echo 'area: '.($width * $height).'<br>';
}

action('printColor', 'blue');
action('printArea', 3, 5);

You could then pass in any function that is visible to the action function. You lose some efficiency but get your action function

Then again, you could also just prepend action functions with 'action_'



TIA, Ralph

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux