Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Larry Garfield

On 2/7/12 1:50 PM, 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


Drupal's coding standards encourage the extra trailing comma on 
multi-line arrays, for all the readability and editability benefits that 
others have mentioned.  We have for years.  Cool stuff. :-)


--Larry Garfield

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



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Robert Cummings

On 12-02-07 02:50 PM, 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.


JavaScript in Internet Crapsplorer spanks you on the bottom every time 
you have a trailing comma in a JS array. That may be where you picked up 
the aversion.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Micky Hulse
On Wed, Feb 8, 2012 at 9:58 AM, Larry Garfield la...@garfieldtech.com wrote:
 Drupal's coding standards encourage the extra trailing comma on multi-line
 arrays, for all the readability and editability benefits that others have
 mentioned.  We have for years.  Cool stuff. :-)

Yah, I love that syntax guideline/rule in Python (tuples and other
things). I will definitely start doing this in PHP for arrays.

I am just surprised that there wasn't an older version of PHP that did
not allow this... I must have picked up this habit via my JS coding
knowledge. :D

Thanks again all!

Cheers,
Micky

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



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Micky Hulse
On Wed, Feb 8, 2012 at 10:08 AM, Robert Cummings rob...@interjinn.com wrote:
 JavaScript in Internet Crapsplorer spanks you on the bottom every time you
 have a trailing comma in a JS array. That may be where you picked up the
 aversion.

On Wed, Feb 8, 2012 at 10:10 AM, Micky Hulse rgmi...@gmail.com wrote:
 I am just surprised that there wasn't an older version of PHP that did
 not allow this... I must have picked up this habit via my JS coding
 knowledge. :D

Jinx! You owe me a Coke!!! :)

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



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Robert Cummings

On 12-02-08 01:12 PM, Micky Hulse wrote:

On Wed, Feb 8, 2012 at 10:08 AM, Robert Cummingsrob...@interjinn.com  wrote:

JavaScript in Internet Crapsplorer spanks you on the bottom every time you
have a trailing comma in a JS array. That may be where you picked up the
aversion.


On Wed, Feb 8, 2012 at 10:10 AM, Micky Hulsergmi...@gmail.com  wrote:

I am just surprised that there wasn't an older version of PHP that did
not allow this... I must have picked up this habit via my JS coding
knowledge. :D


Jinx! You owe me a Coke!!! :)


The timestamps above clearly show I was first ;)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



[PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
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

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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ashley Sheridan
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




Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Paul M Foster
On Tue, Feb 07, 2012 at 11:50:45AM -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

I've always avoided trailing array commas, but only because I was under
the impression that leaving one there would append a blank array member
to the array, where it might be problematic. Yes? No?

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
Hi Ashley! Thanks for your quick and informative reply, I really
appreciate it. :)

On Tue, Feb 7, 2012 at 12:10 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 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.

Makes sense, thanks!

Gosh, I wonder if I picked up this habit due to my JS coding
knowledge? Anyway, thanks for the clarification. :)

Have an awesome day!

Cheers,
Micky

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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ashley Sheridan
On Tue, 2012-02-07 at 15:15 -0500, Paul M Foster wrote:

 On Tue, Feb 07, 2012 at 11:50:45AM -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
 
 I've always avoided trailing array commas, but only because I was under
 the impression that leaving one there would append a blank array member
 to the array, where it might be problematic. Yes? No?
 
 Paul
 
 -- 
 Paul M. Foster
 http://noferblatz.com
 http://quillandmouse.com
 


I've never experienced any blank elements in my arrays, maybe that was a
bug that only existed in very specific scenarios?

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




Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
On Tue, Feb 7, 2012 at 12:15 PM, Paul M Foster pa...@quillandmouse.com wrote:
 I've always avoided trailing array commas, but only because I was under
 the impression that leaving one there would append a blank array member
 to the array, where it might be problematic. Yes? No?

Yah, ditto! :D

In my few simple tests, using PHP5.x, the last comma is ignored.

Just feels strange to have avoided doing something for so long, only
to learn that it's something I need not worry about! :D

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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
On Tue, Feb 7, 2012 at 12:19 PM, Micky Hulse rgmi...@gmail.com wrote:
 Yah, ditto! :D

$s = 'foo,bar,';
print_r(explode(',', $s));

The output is:

Array
(
[0] = foo
[1] = bar
[2] =
)

That's one instance where I know you have to be cautious about the
trailing delimiter.

I know, this is all noob stuff... Sorry. :D

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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Robert Williams
On 2/7/12 13:15, Paul M Foster pa...@quillandmouse.com wrote:


I've always avoided trailing array commas, but only because I was under
the impression that leaving one there would append a blank array member
to the array, where it might be problematic. Yes? No?

Nope. In fact, it's officially supported syntax:

http://us3.php.net/manual/en/function.array.php

I love it, particularly when used with the already-noted multi-line array
syntax (I don't recommend it with single-line arrangements):

$foo = array(
   1,
   2,
   3,
); //$foo

This makes it dead easy to add, remove, or reorder elements without
worrying about accidentally breaking the syntax. Much like always using
braces around flow-control blocks, this practice makes future bugs less
likely to be born.

Now if only we could have support for trailing commas in SQL UPDATE/INSERT
field and value lists


Regards,
Bob


--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/





Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ashley Sheridan
On Tue, 2012-02-07 at 12:26 -0800, Micky Hulse wrote:

 On Tue, Feb 7, 2012 at 12:19 PM, Micky Hulse rgmi...@gmail.com wrote:
  Yah, ditto! :D
 
 $s = 'foo,bar,';
 print_r(explode(',', $s));
 
 The output is:
 
 Array
 (
 [0] = foo
 [1] = bar
 [2] =
 )
 
 That's one instance where I know you have to be cautious about the
 trailing delimiter.
 
 I know, this is all noob stuff... Sorry. :D
 


That's because it's not an array you've got the trailing delimiter on,
it's a string. We were talking about commas on the end of the last
element in the array, like:

$var = array(
'foo',
'bar',
);

That only contains two elements, and won't have a hidden 3rd at any
time.

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




Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
On Tue, Feb 7, 2012 at 12:32 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 That's because it's not an array you've got the trailing delimiter on, it's a 
 string.

Right. Sorry, bad example.

it was just the one example I could think of where you could get an
empty element at the end of your array.

Clearly, apples and oranges though.

Thanks!
Micky

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



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ghodmode
On Wed, Feb 8, 2012 at 4:10 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 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?
...
 It's fine in PHP, and some coding practices actually encourage it, for
 example:
...

 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.

I believe this behavior was inherited from Perl.  I used Perl before I
used PHP and it was considered a feature for exactly the reason Ash
gave.

I think that problems with Perl may have originally inspired the
creation of PHP, at least in part.  But they kept the good parts.
This is just my perception.  To confirm it, I'd have to ask our BDFL
:)

--
Vince Aggrippino
a.k.a. Ghodmode
http://www.ghodmode.com


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



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