Re: Arrays: Comma at end?
| From: | Robert Williams | Date: | Tue, 07 Feb 2012 20:30:06 +0000 |
| Subject: | Re: Arrays: Comma at end? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316545@lists.php.net to get a copy of this message | ||
On 2/7/12 13:15, "Paul M Foster" <paulf@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).