Calling `static::method` from a non-static method results in a non-static call
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
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)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked __call() and __callStatic documentation and review how it describes inaccessible method calls in object and static contexts. Compare those statements with the provided static::method() examples. Done means the documentation clearly explains which magic method is invoked and how the :: and -> operators affect the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100