note 120233 added to function.get-class
| From: | XyQrTw | Date: | Mon, 28 Nov 2016 22:18:06 +0000 |
| Subject: | note 120233 added to function.get-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-207729@lists.php.net to get a copy of this message | ||
To get class name without the Namespace you can use easily this trick :
<?php
namespace My\Long\Namespace;
class MyClass {
static function getClassName() {
return basename(__CLASS__);
// or with get_class();
return basename(get_class());
}
}
echo \My\Long\Namespace\MyClass::getClassName(); // Display : MyClass
?>
----
Server IP: 72.52.91.14
Probable Submitter: 78.116.7.33
----
Manual Page -- http://php.net/manual/en/function.get-class.php
Edit -- https://master.php.net/note/edit/120233
Del: integrated -- https://master.php.net/note/delete/120233/integrated
Del: useless -- https://master.php.net/note/delete/120233/useless
Del: bad code -- https://master.php.net/note/delete/120233/bad+code
Del: spam -- https://master.php.net/note/delete/120233/spam
Del: non-english -- https://master.php.net/note/delete/120233/non-english
Del: in docs -- https://master.php.net/note/delete/120233/in+docs
Del: other reasons-- https://master.php.net/note/delete/120233
Reject -- https://master.php.net/note/reject/120233
Search -- https://master.php.net/manage/user-notes.php