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 lawrence k on 04/16/07 16:45

On Apr 16, 1:48 am, "Martin Mandl - m2m tech support"
<martin.ma...@gmail.com> wrote:
> 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'];
> }

I should just always remember to pass an associative array instead of
a list of arguments? Well, okay, that is kind of obvious. The syntax
is slightly cleaner in Ruby, but sure, we can all do that in PHP too.

 

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

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