[wp-hackers] echo and return
lowmagnet at lowmag.net
lowmagnet at lowmag.net
Tue Jul 27 15:17:05 UTC 2004
On Tue, Jul 27, 2004 at 04:10:34PM +0200, Szilveszter Farkas wrote:
> SM> my_function( array( "foo" => $foo, "option" => true, "whatever" => 1) );
>
> after following this thread for quite a while, this is the best solution
> i could find for the problem. of course in this case the user has to
> be a bit familiar with php, too (but on the other hand it's not easy
> to get used to url type parameters as a newbie either).
It seems that this would become the syntax:
<?php echo the_date(array("before" => "<h2>", "after" => "</h2>")); ?>
A combination of well-designed keys and array passing would give us three benefits:
1. The array syntax uses "x" => "a", which is easier to read due to allowance for whitespace.
2. The array syntax provides run-time checking, while the urlencoded parameters do not.
3. The array syntax, when used with meaningful parameters, is self-documenting.
It also provides a detriment:
1. The default would be all-or-nothing in the function declaration:
...( $input = array("foo" => "bar") )
would be completely overridden if you set the input to:
...( array("baz" => "fizzle") ); results in:
Array([baz]=>"fizzle") (note lack of '[foo]=>"bar"')
We would have to override individual keys with the array_merge function:
$settings = array_merge($defaults, $input);
This will push the new input over the default. From the manual:
" If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. "
http://www.php.net/manual/en/function.array-merge.php
Any takers on this technique?
-eli
More information about the hackers
mailing list