[wp-hackers] echo and return

Stephen Minutillo steveminutillo at gmail.com
Tue Jul 27 13:54:41 UTC 2004


On Mon, 26 Jul 2004 14:19:51 -0500, Ryan Boren <ryan at boren.nu> wrote:
> Yep.  I personally like named parameters.  The main reason we use them
> in WP is to make it possible to change the default value of parameter
> number 12 without having to set values for parameters 1 - 11.  Further,
> time and time again I see reports in the forums from people who tried to
> do "foo=bar" in a template tag.  Perhaps html tag attributes and query
> strings have people thinking in terms of named parameters.

Functions that take named parameters can be useful, but the URL
encoding seems really strange and error prone.  What if you need to
pass something with spaces?  Or an ampersand?  Is the template tag
user supposed to be calling "urlencode" on all the values?

There is another way to get named parameters, that I think is much
cleaner and clearer: associative arrays.

my_function( array( "foo" => $foo, "option" => true, "whatever" => 1) );

Then 'my_function' can examine the array passed in and determine what
to do.  You save all the work (and avoid all the errors associated
with) stringifying and unstringifying the arguments.  And it becomes
possible to pass in more complicated data structures, for example,
$foo above could have itself been an array, or a file handle, or
something else that is hard to stringify.


Steve Minutillo



More information about the hackers mailing list