php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33230 Array() attepts comma before the closing ) and it is not mentioned
Submitted: 2005-06-03 13:31 UTC Modified: 2005-06-03 13:34 UTC
From: phpbug at munaw dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.11 OS: windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbug at munaw dot com
New email:
PHP Version: OS:

 

 [2005-06-03 13:31 UTC] phpbug at munaw dot com
Description:
------------
Hello,

As I know, array() should not accept comma after the last element but it does and var_export generates it the same way. If it accepts this syntax, it could be mentioned in the documentation.

Reproduce code:
---------------
echo phpversion()."\n";
$array = array(
	'1' => 'one',
	'2' => 'two',
	'3' => 'three', // <-comma
);
var_export($array);


Expected result:
----------------
Parse error saying unexpected '(' or something like this.

Actual result:
--------------
4.3.11
array (
  1 => 'one',
  2 => 'two',
  3 => 'three',
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-03 13:34 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

"Having a trailing comma after the last defined array entry, while unusual, is a valid syntax."
http://www.php.net/manual/en/function.array.php
 [2005-06-03 13:34 UTC] phpbug at munaw dot com
In docs it says
 "Having a trailing comma after the last defined array entry, while unusual, is a valid syntax."
Oops...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 08:01:34 2025 UTC