[wp-hackers] echo and return
lowmagnet
lowmagnet at lowmag.net
Tue Jul 27 16:39:44 UTC 2004
On Tue, Jul 27, 2004 at 12:20:54PM -0400, Stephen Minutillo wrote:
> By the way I think this style should not be used in general, only in
> the very few cases where "normal" argument lists wouldn't work, for
> whatever reason, for example if the argument list is very long, or too
> many of the arguments are optional. For example, 'the_date' doesn't
> need named parameters, but arguably 'wp_list_cats' does.
<?php the_date('date_format','before','after',display); ?>
Could become:
<?php echo get_the_date( array( 'date_format' => 'Y/m/d', 'before' => '<h2>', 'after' => '</h2>') ); ?>
> And bringing this thread back around to the original topic, I agree
> that there should be a convention for which functions echo directly to
> the page, and which return strings. For the "template tags", both
> options should be available. I'm not quite sure whether that
> convention should be a standard parameter, or having two parallel sets
> of functions, though.
I propose the following:
<?php echo get_the_date( paramsarray ); ?>
I also propose that anything using the 'get_' prefix should use the parameter array, else we are left with less consistency.
any issues with the get_ name? I know there are some functions that use it currently, so I know it may be an issue. Of the top of my head, get_links() would be broken if you passed an array instead of a string for settings.
alternately, there's always a plain '_' prefix, but that is reserved normally for private function names. Or 'g_', but some people parse that as 'global'.
There is also the matter of what you want to have tossed back and forth from functions. Do you simply want a string, or as in the case of lists, do you want the list returned as a nested array? The mind spins from the implications.
-eli
More information about the hackers
mailing list