[php-src] Issue #8199: Calling `static::method` from a non-static method results in a non-static call
| From: | someonewithpc | Date: | Sun, 13 Mar 2022 22:12:38 +0000 |
| Subject: | [php-src] Issue #8199: Calling `static::method` from a non-static method results in a non-static call | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240327@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8199
Author: someonewithpc
### Description
The following code:
```php
<?php
class A
{
public static function __callStatic(string $method, array $args): void
{
echo "Called static '{$method}'\n";
}
public function __call(string $method, array $args): void
{
echo "Called non static '{$method}'\n";
}
public static function static_foo(): void
{
static::foo();
}
public function non_static_foo(): void
{
static::foo();
}
}
A::static_foo(); // Output: Called static 'foo'
(new A)::static_foo(); // Output: Called static 'foo'
(new A)->static_foo(); // Output: Called static 'foo'
(new A)->non_static_foo(); // Output: Called non static 'foo'
```
Resulted in this output:
```
Called static 'foo'
Called static 'foo'
Called static 'foo'
Called non static 'foo'
```
But I expected this output instead:
```
Called static 'foo'
Called static 'foo'
Called static 'foo'
Called static 'foo'
```
[The __call and __callStatic
documentation](https://www.php.net/manual/en/language.oop5.overloading.php#object.callstatic)
mentions
> [__call()](https://www.php.net/manual/en/language.oop5.overloading.php#object.call) is
> triggered when invoking inaccessible methods in an object context.
Which may mean this is intended behaviour, but it is rather confusing.
### PHP Version
8.1.3, 8.1.1
### Operating System
Arch Linux and Alpine (docker)