note 114333 deleted from language.oop5.traits by cmb
| From: | cmb@php.net | Date: | Sun, 01 Dec 2019 08:55:25 +0000 |
| Subject: | note 114333 deleted from language.oop5.traits by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213331@lists.php.net to get a copy of this message | ||
Note Submitter: tomasz at marcinkowski dot pl
----
Unlike the __CLASS__ constant, which returns name of a class implementing a trait, the __METHOD__
constant returns the trait method name. You might find it useful.
Example:
<?php
namespace XXX;
trait Ta {
public function test1() {
return sprintf('class: %s, method: %s, trait: %s', __CLASS__, __METHOD__, __TRAIT__);
}
}
class A {
use Ta;
}
$a = new A();
var_dump($a->test1()); // class: XXX\A, method: XXX\Ta::test1, trait: XXX\Ta
?>