Re: Arrays: Comma at end?

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

 



On Tue, 2012-02-07 at 11:50 -0800, Micky Hulse wrote:

> Was there ever a time when having a comma at the end of the last array
> element was not acceptable in PHP?
> 
> I just did a few quick tests:
> 
> <https://gist.github.com/1761490>
> 
> ... and it looks like having that comma ain't no big deal.
> 
> I can't believe that I always thought that having the trailing comma
> was a no-no in PHP (maybe I picked that up from my C++ classes in
> college? I just don't remember where I picked up this (bad) habit).
> 
> I would prefer to have the trailing comma... I just can't believe I
> have avoided using it for all these years.
> 
> Thanks!
> Micky
> 


It's fine in PHP, and some coding practices actually encourage it, for
example:

$var = array(
    'element',
    'element',
    'element',
);

It's easy to add and remove elements without making sure you have to
check the trailing comma. It's also OK in Javascript to use the trailing
comma, as long as you don't mind things not working on IE, which is the
only browser that has issues with it. As far as PHP goes though, it's
fine.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



[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