I have following Code in the Parent Class:
class parent {
/**
* Memory of the instances of the classes.
* @since 1.0.0
* @access protected
* @static
* @var array
*/
protected static $instances = [];
/**
* Singleton
* Thanks to: https://stackoverflow.com/a/45500679/8148987
* @since 1.0.0
* @access public
* @static
* @return object
*/
public static function instance() {
if ( empty( self::$instances[static::class] ) ) {
$instance = new static();
self::$instances[static::class] = $instance;
} else {
$instance = self::$instances[static::class];
}
return $instance;
}
}
The Child Class:
class child extends parent {
public function test() {
}
}
I can do following with this code:
$class_child = child::instance();
But PHP is not aware of the method test().
If I write $class_child-> no proposals are listed. What canI do? The solution mentioned here https://stackoverflow.com/a/32014968/8148987 will not work in my case.
Aucun commentaire:
Enregistrer un commentaire