Anyone know if it's possible in PHP to force a class to extend or implement an interface without the child class having to declare it?
Example:
interface Requirements
{
public function __construct();
public function kittens();
}
class DingleBerry
{
public function __construct()
{
// yadda yadda yadda
}
}
// Example of my initial hope
// of what you could do
$kittens = new DingleBerry implements Requirements;
Obviously that doesn't work, but I need a way of loading in classes that have no predetermined knowledge of the interface requirements but are forced to abide by them.
My overall goal is to check to see if the class implements the Requirements BEFORE its loaded and it's constructor is called.
So I CANNOT use this:
interface Requirements
{
public function __construct();
public function kittens();
}
class DingleBerry
{
public function __construct()
{
// DO BAD STUFF (i.e. eat your soul)
}
}
// Example of what I CANNOT
// do.
$kittens = new DingleBerry;
if( !($kittens instanceof Requirements) )
{
// eat pizza.
}
Because then DingleBerry's constructor is called before I can check if it implements the Requirements. Dig?