<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

class ParentClass
{
    public function __construct()
    {
        
    }
    
    public static function create()
    {
        $class = get_called_class();
        return new $class;
    }

    public static function testMethod()
    {
        echo 'this should work in both classes'.PHP_EOL;
    }

}

class ChildClass extends ParentClass
{

    public function __construct(string $param1 = 'test', string $param2)
    {
        
    }

}

function testClass(ParentClass $class)
{
    $object = $class::create();
    $object::testMethod();
}

testClass(new ParentClass());
testClass(new ChildClass('1', '2'));


