The documentation says that :
"self" is an instanceof the same class as the one in which the type declaration is used.
while "static" is an instanceof the same class as the one the method is called in.
But it does not provide an example, and here I want to provide an example,
We have 2 classes, the first one is "A", and the second is "B". Let us declare 2 methods in the class "A" that use "self" and "static", then we will make "B" extend the "A" class, and then call the methods from "B" and "A", then compare.
example :
<?php
class A
{
public static function withSelf(): self
{
return new self();
}
public static function withStatic(): static
{
return new static();
}
}
class B extends A {}
var_dump(A::withSelf());
var_dump(B::withSelf());
var_dump(A::withStatic());
var_dump(B::withStatic());
?>