Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

variable number of args

0 views
Skip to first unread message

bill

unread,
Nov 5, 2009, 9:44:07 AM11/5/09
to
I have a function that always has at least one argument and may
have a 2nd.

Can I pass the first by reference and then check to see if there
is a 2nd, e.g:

procedure foo($bar){

echo $bar;

$numargs = func_num_args();
if ($numargs) {
$bar2 = func_get_arg(1);
echo $bar2;
...
}

or must I get both args using func_get_arg() or func_get_args() ?

bill

Jerry Stuckle

unread,
Nov 5, 2009, 10:25:31 AM11/5/09
to

Did you try it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

Captain Paralytic

unread,
Nov 5, 2009, 10:56:32 AM11/5/09
to

Or even
procedure foo($bar, $bar2 = NULL){

Curtis Dyer

unread,
Nov 6, 2009, 12:02:45 AM11/6/09
to
On 05 Nov 2009, Captain Paralytic <paul_l...@yahoo.com> wrote:

> On 5 Nov, 14:44, bill <nob...@spamcop.net> wrote:

<snip>

> Or even
> procedure foo($bar, $bar2 = NULL){

ITYM: function foo($bar, $bar2 = NULL){
^^^^^^^^

--
Curtis Dyer
<? $x='<? $x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>

Captain Paralytic

unread,
Nov 6, 2009, 6:00:47 AM11/6/09
to
On 6 Nov, 05:02, Curtis Dyer <dye...@gmail.com> wrote:

> On 05 Nov 2009, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
> > On 5 Nov, 14:44, bill <nob...@spamcop.net> wrote:
>
> <snip>
>
> > Or even
> > procedure foo($bar, $bar2 = NULL){
>
> ITYM:  function foo($bar, $bar2 = NULL){
>        ^^^^^^^^
I just copied the line from the OP. I didn't even read that it said
procedure, I read it as function!

Danny Wilkerson

unread,
Nov 6, 2009, 6:43:29 AM11/6/09
to
have you considered passing an array?

function doit($a=array()){
echo 'I have '.count($a).' items!';
foreach ($a as $key => $value) {
echo "Key: $key; Value: $value<br />\n";
}
}

Michael Fesser

unread,
Nov 7, 2009, 8:14:39 PM11/7/09
to
.oO(Danny Wilkerson)

>have you considered passing an array?

Should always be the last option. If you just have a small number of
arguments, maybe even with some being optional, explicitly define them
like that.

Passing them all as an array not only complicates the code, but will
also interfere with many features in modern IDEs like code completion,
auto documentation and debugging.

Micha

0 new messages