[php-src] Issue #10367: Using variable variables in arrow functions
| From: | alexNecroJack | Date: | Wed, 18 Jan 2023 13:50:14 +0000 |
| Subject: | [php-src] Issue #10367: Using variable variables in arrow functions | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243485@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10367
Author: alexNecroJack
### Description
The following code:
```php
<?php
// Variable variable.
$a = 'b';
$b = 'target';
var_dump($$a == $b);
// Anon function with inclusion of scope.
$fn = function($c) use($b) {
var_dump($$c == $b);
};
$fn($a);
// I can use scope within using variable variable.
$fn = fn($c) => $$c == $b;
var_dump($fn($a));
// I can't return it though.
$fn = fn($c) => $$c;
var_dump($fn($a));
```
Resulted in this output (PHP 7.4+) :
```
bool(true)
bool(true)
bool(true)
Warning: Undefined variable $b in /home/user/scripts/code.php on line 20
NULL
```
But I expected this output instead:
```
bool(true)
bool(true)
bool(true)
string('target')
```
Credits and all to: @kschatzle
I'm only sharing this (found on google, github issues search returned nothing, documentation
states nothing...)
[ArrowFunctionScoping](https://gist.github.com/kschatzle/ce7f49df41f26093079dcc1b45fbefe7)
### PHP Version
PHP 8.1.12, PHP 8.0.25
### Operating System
https://onlinephp.io/