note 115908 deleted from language.oop5.traits by cmb

From: Date: Sun, 01 Dec 2019 08:56:27 +0000
Subject: note 115908 deleted from language.oop5.traits by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213334@lists.php.net to get a copy of this message
Note Submitter: angel dot ayora at gmail dot com ---- The traits can be used if are inherited from a parent class, but the trait still belong to parent class: <?php trait Singleton { private static $instance = null; public static function singleton() { if( self::$instance == null ) { self::$instance = new self(); } return self::$instance; } } class A { use Singleton; private function __construct(){} } class B extends A { private function __construct(){} } $b = B::singleton(); echo get_class($b); //Output: A ?>

« previous php.notes (#213334) next »