[php-src] Issue #11724: Constructor Property promotion applies parameter name rules to properties

From: Date: Mon, 17 Jul 2023 10:23:13 +0000
Subject: [php-src] Issue #11724: Constructor Property promotion applies parameter name rules to properties
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244981@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11724
Author: jrfnl

### Description

The following code:

```php
<?php
class Foo {
    private array $_GET; // OK.
}

class Bar {
    public function __construct( private array $_GET ) {} // Same thing, but using CPP syntax sugar
results in fatal error.
}
```

Resulted in this output:
```
Fatal error: Cannot re-assign auto-global variable _GET in /in/ZA5Bk on line 8
```

But I expected this output instead:
_No error, fatal or otherwise._

### Additional context

Since PHP 5.4, parameter names shadowing superglobals are forbidden. However, this restriction does
not apply to property names.

When using the constructor property promotion, that restriction is, however, applied to properties
too.


### PHP Version

PHP 8.0+

### Operating System

_No response_


Thread (1 message)

  • jrfnl
« previous php.bugs (#244981) next »