473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

can one get the name of parameters passed to a function?

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.

I'm wondering if there is anyway to emulate the Ruby style with
something like this:

http://us2.php.net/manual/en/function.func-get-args.php

Is there a way to get the parameters as an associative array? A
numerically indexed array is just as useless as the normal style of
passing arguments.

Apr 16 '07 #1
3 1908
On Apr 16, 7:19 am, "lawrence k" <lkrub...@geocities.comwrote:
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

Apr 16 '07 #2
On Apr 16, 1:48 am, "Martin Mandl - m2m tech support"
<martin.ma...@gmail.comwrote:
On Apr 16, 7:19 am, "lawrence k" <lkrub...@geocities.comwrote:
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.
Apr 16 '07 #3
On 15 Apr 2007 22:19:57 -0700, "lawrence k" <lk******@geocities.comwrote:
>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.

I'm wondering if there is anyway to emulate the Ruby style with
something like this:

http://us2.php.net/manual/en/function.func-get-args.php

Is there a way to get the parameters as an associative array? A
numerically indexed array is just as useless as the normal style of
passing arguments.
For an insane solution, search Google Groups for "This calls for the power of
Bobo the Clown" (seriously).

Otherwise, pass an associative array.
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Apr 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
6
by: dharmadam | last post by:
Is it possible to pass a column name or the order of the column name in the DB2 table table function. For example, I want to update the address of a person by passing one of the address column name...
1
by: Julia | last post by:
Hi, I have been asked this before but I think that I didn't explain myself well I am using exception and logging and I would like to log the parameters which was passed to the function...
3
by: danbraund | last post by:
Hi everyone, I'm a long time C coder, who is coding his final year project in C++ to run under the MIT click routing system. Being fairly new to the OO side of the language, my problem is this: ...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
4
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript....
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
3
by: Matthew Keene | last post by:
I would like to be able to call a specific classmethod on a class name that is going to be passed from another parameter. In other words, I have a call that looks something like: x = Foo.bar()...
19
by: JRough | last post by:
I have used this function to create a string called $headers: function GetHeaders($file_name){ return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th> <th><a href='"....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.