laudirbispo / classname
A simple class to get object names
1.2.1
2019-02-26 13:37 UTC
This package is auto-updated.
Last update: 2025-03-27 05:39:53 UTC
README
This package can get the name of the base class, the namespace, the canonical name, the parent class name, and the path of an object. It can have as a parameter a string as a class name or an object to get its class.
This class was nominated for the Innovation award from phpclasses.org
Installation
Install the latest version with
$ composer require laudirbispo/classname
Basic Usage
<?php use laudirbispo\classname\ClassName; $exampleClass = 'namespace\namspace2\MyClass'; // or $exampleClass = new MyClass; var_dump(ClassName::full($exampleClass)); // return string 'namespace\namspace2\MyClass' (length=27) var_dump(ClassName::namespace($exampleClass)); // return string 'namespace\namspace2' (length=19) var_dump(ClassName::short($exampleClass)); //return string 'MyClass' (length=7) var_dump(ClassName::canonical($exampleClass)); // return string 'namespace.namspace2.MyClass' (length=27) // Get parent class name or null // @param $return string - full, namespace, canonical short - default is dull var_dump(ClassName::getParent($exampleClass, string $return = 'full'));
It's really very simple
Author
Laudir Bispo - laudirbispo@outlook.com - https://twitter.com/laudir_bispo
License
ClassName is licensed under the MIT License - see the LICENSE
file for details
Free Software, Hell Yeah!