[php-src] Issue #20188: Invalid function reference within the same namespace
| From: | infinitum11 | Date: | Thu, 16 Oct 2025 09:36:51 +0000 |
| Subject: | [php-src] Issue #20188: Invalid function reference within the same namespace | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251072@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20188
Author: infinitum11
### Description
When an eval-defined-namespaced-function is called from within another function of that namespace,
it refers to the global function instead of the locally defined function.
https://3v4l.org/0PbCO
```php
<?php
namespace Loader {
function register() {
eval(<<<EOPHP
namespace App;
function strlen(\$str) { return 20; }
EOPHP
);
}
}
namespace App {
function run($str) {
echo __NAMESPACE__, PHP_EOL;
echo strlen($str), PHP_EOL;
}
run("foo");
\Loader\register();
run("bar");
}
```
Resulted in this output:
```
App
3
App
3
```
But I expected this output instead:
```
App
3
App
20
```
However, if we call the
strlen() function from the global scope of the namespace App,
we get an expected result
https://3v4l.org/mQuUI
```php
<?php
namespace Loader {
function register() {
eval(<<<EOPHP
namespace App;
function strlen(\$str) { return 20; }
EOPHP
);
}
}
namespace App {
echo __NAMESPACE__, PHP_EOL;
echo strlen("foo"), PHP_EOL;
\Loader\register();
echo __NAMESPACE__, PHP_EOL;
echo strlen("foo"), PHP_EOL;
}
```
Resulted in this output:
```
App
3
App
20
```
### PHP Version
```plain
8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
```
### Operating System
_No response_