php.net |  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
 [2018-05-31 16:43 UTC] kmvan dot com at gmail dot com
Description:
------------
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 = [
  'a',
  'b',
];


Test script:
---------------
<?php
\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', ]; "

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-31 16:50 UTC] peehaa@php.net
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] peehaa@php.net
-Status: Open +Status: Not a bug
 [2018-05-31 17:14 UTC] peehaa@php.net
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);
Array
(
    [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: Mon Apr 06 23:01:24 2020 UTC