[wp-hackers] echo and return
Owen Winkler
ringmaster at midnightcircus.com
Tue Jul 27 17:15:35 UTC 2004
This discussion is insanity. Assuming that there is a call for a change
at all, here's my pithy suggestion:
Make template functions always echo by default. The first function
parameter is either a querystring or an array. The second function
parameter optionally turns off the echo. Template functions always
return the value they would have echoed/did echo.
Benefits:
Breaks less legacy code.
Arrays as parameters, benefits as mentioned in previous post.
Querystrings still work for functions that already call with them.
Code to accomplish this:
function fix_params($params, $defaults = array())
{
if(!is_array($params)) {
parse_str($params, $ary);
return array_merge($defaults, $ary);
}
return array_merge($defaults, $params);
}
// This is a sample template function
function the_something($params, $doecho = true) {
$params = fix_params($params, array('default' => 'setting'));
...
if($doecho) echo $result;
return $result;
}
By the way, David, that's a pretty neat function you wrote to synth the
getters.
Owen
More information about the hackers
mailing list