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:7
Avg. Score:4.0 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:4 (80.0%)
Same OS:4 (80.0%)
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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cweiske@php.net
New email:
PHP Version: OS:

 

 [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: Tue Mar 19 05:01:29 2024 UTC