‹ Post Number Two Thousand, Six Hundred and Fifty-Two •
I was editing some code today and saw what looked like an error to me, but nothing was broken on the code I was looking at it, so I was prompted to look it up. And indeed, in PHP:
“Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.”
So sayeth the documentation for PHP: array
If it says it in there, it must be true.
So this is legal php:
$my_array = array(‘foo’,’bar’,’bat’,);
... which, as I said, looks so bizarre to me.
Tags: web-programming

3 comments
Comments feed for this article
Trackback link
http://artlung.com/blog/2007/01/24/trailing-commas-in-an-array-ok-in-php/trackback/
January 25, 2007 at 7:14 am
Sassy
gross!
January 25, 2007 at 11:27 am
Joe Crawford
I know! Right?
I guess they classify this stuff as “syntactic sugar”—but it just looks ugly/lazy to me!
January 26, 2007 at 8:21 am
Sassy
what is the value of the last element? An empty string. Syntactic sugar my foot