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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
31 - 28 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 03:03:33 2021 UTC