确定使用parent :: __ construct()的子类;

I have a situation where I need to pass the name of the child class back to the parent class in order to take some action.

The way I have it set up at the moment is:

class SomeParentClass {

    public function __construct($c = false){
        ...
    }

}

class SomeChildClass extends SomeParentClass {

    public function __construct(){
        parent::__construct(__CLASS__){
            ...
        }
    }

}

This will pass the name of the child class back to the parent, but if the child class does not do this then the variable $c will retain the bool value false.

It works, it makes sense, but is this the cleanest way to do this? Is there a way to auto detect which child class has called parent::__construct() without passing it as a variable?

Many thanks

<?php
class SomeParentClass {

    public function __construct($c = false){       
        echo get_called_class();
    }

}

class SomeChildClass extends SomeParentClass {

    public function __construct(){
        parent::__construct(__CLASS__);       
    }

}

class OtherChildClass extends SomeParentClass {
    public function __construct(){
        parent::__construct(__CLASS__);  
    }

}

$a = new SomeChildClass();
$b = new OtherChildClass();

I could be wrong, but under normal circumstances, the parent shouldn't be aware of its child classes. I'm sure there's a better way to do what you're trying to do.

Exceptions to this "rule" is perhaps base classes that expose static (optionally final) constructors which are then called with a child class prefixed, e.g.

class Parent
{
    public final static function create()
    {
        return new static;
    }
}

class Child extends Parent
{
    public function __construct()
    {
        // special code here
    }
}

var_dump(Child::create());