I am looking for a way where you can call a static method in a class, which will create an instance of itself. I would like it so it isn't possible to instantiate the class outside of itself. I have tried this, but I get an error saying Cannot instantiate abstract class (Which I assumed would happen).
abstract class Test {
public function __construct($item){
}
public static function from($item){
return new Test($item);
}
public function testFunc(){
// Do some stuff
return $this;
}
}
It's usage would look something like this:
// Valid
Test::from($myItem)->testFunc();
// Invalid
(new Test($myItem))->testFunc();
Is there any way to do something like this?