You are here: Re: can one get the name of parameters passed to a function? « PHP Programming Language « IT news, forums, messages
Re: can one get the name of parameters passed to a function?

Posted by Martin Mandl - m2m tech support on 04/16/07 05:48

On Apr 16, 7:19 am, "lawrence k" <lkrub...@geocities.com> wrote:
> One thing I like about Ruby is the use of symbols when passing
> function parameters to a function. One thing I dislike about PHP is
> that if a function has 4 optional parameters but you want to do
> something with the 4th one, you need to put in something, perhaps
> empty strings, for the first 3 parameters, even though you've no
> interest in using them.

Dear Lawrence,

try to modify your function from

function dummy($param1 = '', $param2 = '', $param3 = '', $param4 =
'') {
if ($param1) echo $param1;
if ($param2) echo $param2;
if ($param3) echo $param3;
if ($param4) echo $param4;
}

to

function dummy(&$params) {
if (isset($params['first'])) echo $params['first'];
if (isset($params['second'])) echo $params['second'];
if (isset($params['third'])) echo $params['third'];
if (isset($params['forth'])) echo $params['forth'];
}


This way you can use the function e.g. with the fourth parameter only
when you call

dummy(array('forth' => 'testvalue'));


Good luck
Martin


------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация