|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76398 Function `php_strip_whitespace` with multiline array.
Submitted: 2018-05-31 16:43 UTC Modified: 2018-05-31 17:14 UTC
From: kmvan dot com at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 7.1.18 OS: Windows/Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: kmvan dot com at gmail dot com
New email:
PHP Version: OS:


 [2018-05-31 16:43 UTC] kmvan dot com at gmail dot com
If a two-dimensional multiline array ends with a comma. The function `php_strip_whitespace` can not trim the last comma in single line, so cause parse error.

File a.php:
<?php $a = [

Test script:
\var_dump(\php_strip_whitespace(__DIR__ . '/a.php'));
// output: string(26) "<?php $a = [ 'a', 'b', ]; "

Expected result:
// output: string(25) "<?php $a = [ 'a', 'b' ]; "

Actual result:
// output: string(26) "<?php $a = [ 'a', 'b', ]; "


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-31 16:50 UTC]
Why would it strip commas? And why would it result in a parse error?

Feels like there is something else wrong.
 [2018-05-31 17:05 UTC] kmvan dot com at gmail dot com
Because `$a = [ 'a', 'b', ];` is a parse error.

The comma after 'b' should trim in single line or cause parse error.
 [2018-05-31 17:14 UTC]
-Status: Open +Status: Not a bug
 [2018-05-31 17:14 UTC]
That does not result in a parse error and is perfectly fine PHP code.
 [2018-05-31 17:24 UTC] spam2 at rhsoft dot net
> Because `$a = [ 'a', 'b', ];` is a parse error

says who?

this is not and was not a parse-error over decades and it#s even what proper codebases for long-arrays always do when each item is in a seperate line - please verify before you pretend such false statements

php > $a = [ 'a', 'b', ];
php > print_r($a);
    [0] => a
    [1] => b
php >
 [2018-06-01 03:48 UTC] kmvan dot com at gmail dot com
Oh, sorry that's my wrong.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Mar 31 20:01:24 2020 UTC