Re: Associative Arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2008-06-19 at 19:59 -0700, Paul Novitski wrote:
> At 6/19/2008 07:36 PM, Robert Cummings wrote:
> > > >>     54321 => array(
> > > >>       'mail' => 'asdf@xxxxxxxx',
> > > >>       'companyName' => 'Asdfu Corp.',
> > > >>     ),
> > > >>   );
> > > >
> > > >
> > > > This is the right PHP syntax, except that you've got an extraneous comma
> > > > before the closing parenthesis of each array that's going to throw a
> > > > parse error.
> > >
> > > Actually that's allowed (and by design too) :)
> >
> >Yep, it's there to primarily simplify generated PHP code. Additionally,
> >it sure makes commenting out chunks simple since you don't need to
> >comment out the preceding comma if commenting out the last entry.
> 
> 
> Thanks.  I could have sworn I'd gotten parse errors on that.  Damned 
> cross-language memory leakage...
> 
> I've gotten into the habit of writing comma-delimited lists like so:
> 
>          (item
>          ,item
>          ,item
>          ,item
>          );
> 
> which works for functions with long parameter lists and SQL field 
> lists as well as arrays.

Unfortunately, commenting out the first entry brings you back to the
same problem of commenting out the last entry in the event trailing
commas weren't supported. You've merely reversed the problem...
unnecessarily so ;)

Personally, I use two styles of long parameters in my code (I still try
to write code to 78 characters wide). If a single line drop will suffice
I do the following:

    functionWithLotsOfParams(
        $param1, $param2, $param3, $param4, $param5, $param6 );

If I would still get wrapping, then I use a block style:

    functionWithFarToManyParamsOrLongVariableNames
    (
        $param1, $param2, $param3, $param4, $param5, $param6,
        $param7, $param8, $param9, $paramA, $paramB, $paramC
    );

Unlike array declarations, it's unlikely the parameter count will change
often :)

Cheers,
Rob.

Ps. Please Tedd... don't show an example using your weird ass
indentation style -- it makes me shudder that I might ever have to
maintain someone's code that follows your style ;)

-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux