note 115908 added to language.oop5.traits
| From: | angel dot ayora at gmail dot com | Date: | Mon, 13 Oct 2014 14:28:06 +0000 |
| Subject: | note 115908 added to language.oop5.traits | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200636@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 72.52.91.14
Probable Submitter: 37.133.0.66
----
Manual Page -- http://php.net/manual/en/language.oop5.traits.php
Edit -- https://master.php.net/note/edit/115908
Del: integrated -- https://master.php.net/note/delete/115908/integrated
Del: useless -- https://master.php.net/note/delete/115908/useless
Del: bad code -- https://master.php.net/note/delete/115908/bad+code
Del: spam -- https://master.php.net/note/delete/115908/spam
Del: non-english -- https://master.php.net/note/delete/115908/non-english
Del: in docs -- https://master.php.net/note/delete/115908/in+docs
Del: other reasons-- https://master.php.net/note/delete/115908
Reject -- https://master.php.net/note/reject/115908
Search -- https://master.php.net/manage/user-notes.php