php get class name without namespace – PHP Namespaces

php get class name without namespace – get a PHP class name without the use of namespace and without using reflection.

php get class name without namespace

simple function to get class name without namesapce. php get class name without namespace from string

public function getClassName() {
    $path = explode('\\', __CLASS__);
    return array_pop($path);
}

return substr(strrchr(__CLASS__, "\\"), 1);

PHP get class name without namespace

public function getName() {
    $path = explode('\\', __CLASS__);
    return array_pop($path);
}

php namespace class

<?php
namespace m\name; // see "Defining Namespaces" section

class GetDetails {}
function myfunction() {}
const RANKDTL = 1;

$a = new GetDetails;
$c = new \my\name\GetDetails; // see "Global Space" section

$a = strlen('welcome'); // see "Using namespaces: fallback to global
                   // function/constant" section

$d = namespace\RANKDTL; // see "namespace operator and __NAMESPACE__
                        // constant" section
$d = __NAMESPACE__ . '\RANKDTL';
echo constant($d); // see "Namespaces and dynamic language features" section
?>

laravel get class name

$lObjectect = $em->find(ContactRelation::class, $userId);
echo get_class($lObjectect);
// Some\Name\Space\Domain\Identity\ContactRelation

Don’t Miss : PHP Config Class To Store Configuration Data

Also Read This ūüĎČ   mysql last inserted id - 3 ways to get last inserted id of a MySQL table

I hope you get an idea about php get class name without namespace.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.