[php-src] Issue #8122: Bug with Hash Comments

From: Date: Sun, 20 Feb 2022 06:09:23 +0000
Subject: [php-src] Issue #8122: Bug with Hash Comments
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239901@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8122
Author: manngo

### Description

The following code:

```php
<?php
	$test = [
		['a','b'],
		['c','d'],
		#['e','f'],
		['g','h'],
	];
	print_r($test);

```

Resulted in this output:

<b>Parse error</b>:  syntax error, unexpected single-quoted string &quot;e&quot;
in <b>…</b> on line <b>…</b>


But I expected this output instead:
```
Array
(
    [0] => Array
        (
            [0] => a
            [1] => b
        )
    [1] => Array
        (
            [0] => c
            [1] => d
        )
    [2] => Array
        (
            [0] => g
            [1] => h
        )
)
```

That is, the #['e','f'] line cause an error. Somehow, PHP has
suddenly forgotten that # is a comment.

The version tested is 8.0.13.

Here are three things that worked:

- Use Version 7.2.2 instead
- Use # ['e','f'] (ie add a space after # in version
8.0.13
- Use //['e','f'] (ie use // with or without space) in
version 8.0.3

From the above I conclude that the described behaviour is unintended.

I was only able to test this on PHP 8.0.13 on Rocky Linux and PHP 7.2.2 on MacOS.

### PHP Version

PHP 8.0.13

### Operating System

Rocky Linux, MacOS


Thread (1 message)

  • manngo
« previous php.bugs (#239901) next »