php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75426 "Cannot use empty array elements" reports wrong position
Submitted: 2017-10-24 12:20 UTC Modified: 2019-01-02 10:39 UTC
Votes:8
Avg. Score:4.1 ± 0.9
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:4 (66.7%)
From: cweiske@php.net Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.2.0RC4 OS:
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
21 + 26 = ?
Subscribe to this entry?

 
 [2017-10-24 12:20 UTC] cweiske@php.net
Description:
------------
If there is a syntax error because there are two consecutive commas in an array, a fatal error is reported:

  PHP Fatal error:  Cannot use empty array elements in arrays in file.php on line 3

The problem is that the line reported is the start of the array definition, not the line at which the error actually is.

This makes it very hard to debug array definitions of 100 lines length.

See https://3v4l.org/Ek6pJ and https://3v4l.org/WJUbZ

Test script:
---------------
<?php
$a = [
    1,
    ,
    3
];

Expected result:
----------------
Line 4 should be reported.

Actual result:
--------------
Line 3 is reported.

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-23 11:06 UTC] andrew dot nester dot dev at gmail dot com
Thanks for pointing this issue! I've just added CR implementing this.
 [2019-01-02 10:39 UTC] nikic@php.net
I've committed a partial fix for this issue at https://github.com/php/php-src/commit/73596c56e7905ce5b7c4f15d551361ee744cad0c. It doesn't actually change anything for the case shown here, but if the array is larger, it will now point to the element before the stray comma.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC