-
Notifications
You must be signed in to change notification settings - Fork 811
Open
Description
Description
The following code:
<?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_method(): void
{
static::method();
}
public function non_static_method(): void
{
static::method();
}
}
A::static_method(); // Output: Called static 'method'
(new A)::static_method(); // Output: Called static 'method'
(new A)->static_method(); // Output: Called static 'method'
(new A)->non_static_method(); // Output: Called non static 'method'
Resulted in this output:
Called static 'method'
Called static 'method'
Called static 'method'
Called non static 'method'
But I expected this output instead:
Called static 'method'
Called static 'method'
Called static 'method'
Called static 'method'
The __call and __callStatic documentation mentions
__call() is triggered when invoking inaccessible methods in an object context.
Which may mean this is intended behaviour, but it is rather confusing.
Essentially, I'd expect the type of method called to be determined by the operator used: ::
or ->
PHP Version
8.1.3, 8.1.1
Operating System
Arch Linux and Alpine (docker)
Metadata
Metadata
Assignees
Labels
No labels