PHP and Python Function Arguments
Posted by mkhairul - February 21, 2007 at 01:02:31 am -Categories: blog
While doing some work, I tried to find about function arguments in PHP. I still prefer python ways of doing things
-
def test(tmp1, tmp2):
-
print tmp1
-
print tmp2
-
-
test(tmp2='woot2', tmp1='woot1')
-
-
>>woot1
-
>>woot2
Thats a nice feature that I wished PHP had. So that I dont have to remember the order of arguments and just type in the "key" and its "values". Its kinda natural that way.
(While I was trying to find a nice syntax highlighting plugins for WP, I tried iG:Syntax Hiliter, works like a charm.)
The best way I can do for php is...
-
-
// tried using the python way..
-
test($tmp2='woot2', $tmp1='woot1');
-
-
woot2
-
woot1
func_get_args() just doesnt cut it.
I traveled this path when I wanted to differentiate between list and associative array. Which leads me to a drupal issues page. Differentiate between associative and numeric php arrays.
*Apparently there's some issues regarding html formatting of symbols > (greater than) which bothers me. It doesnt bother me enough to fix it at this moment. Ah.. priorities.. priorities.
I experimented a little. This is the best that I can do for the moment..
-
'name' => '',
-
'size' => '25',
-
'default' => '',
-
'id' => '',
-
'extra' => '',
-
'desc' => ''
-
);
-
{
-
if(is_assoc($newattr))
-
{
-
foreach($default_value as $attr_name => $attr_value)
-
{
-
$default_value[$attr_name]:'');
-
}
-
}
-
else
-
{
-
$tmp_key = '';
-
$$tmp_key = $newattr;
-
foreach($default_value as $attr_name => $attr_value)
-
{
-
{
-
$$attr_name = $attr_value;
-
}
-
}
-
}
-
}
-
else
-
{
-
{
-
}
-
$tmp_key = '';
-
for($i=0; $i<count($args); $tmp_key="key($default_value);" $$tmp_key="$args[$i];" //$$attr[$i="$newattr[$i];"> $attr_value)
-
{
-
{
-
$$attr_name = $attr_value;
-
}
-
}
-
}
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.
