[php-src] Issue #13812: `self` is synonymous with `static` when used upstream of `get_called_class()`
| From: | GuySartorelli | Date: | Tue, 26 Mar 2024 20:54:13 +0000 |
| Subject: | [php-src] Issue #13812: `self` is synonymous with `static` when used upstream of `get_called_class()` | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246655@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13812
Author: GuySartorelli
### Description
The following code:
```php
<?php
class foo {
static public function getclass() {
var_dump(get_called_class());
}
static public function test() {
self::getclass();
}
}
class bar extends foo {}
bar::test();
```
Resulted in this output:
```text
string(3) "bar"
```
But I expected this output instead:
```text
string(3) "foo"
```
## Additional context
In the [docs about late static
binding](https://www.php.net/manual/en/language.oop5.late-static-bindings.php) it says
> Static references to the current class like
self:: or
> __CLASS__ are resolved using the class in which the function
> belongs, as in where it was defined
This leads me to believe that get_called_class() should be returning foo,
because that is the class where the self:: was defined, and
get_called_class() is called _downstream_ from that.
It's possible that everything's working as it's supposed to, but in that case I
believe the documentation for late static binding needs to be updated to include this edge case as
it's extremely unintuitive - it feels like self is just a synonym for
static in this scenario.
### PHP Version
PHP 8.1.27
### Operating System
_No response_