Destramic Posted August 30, 2014 Share Posted August 30, 2014 when trying to call get_class($this) it will return the namespace of my class Application\Models\User_Model But what im really after is just User_Model... is there a way of actually getting the class name and not the namespace itself? thought i'd ask before making a class for that...thank you Quote Link to comment https://forums.phpfreaks.com/topic/290755-get_classthis-with-namespaces/ Share on other sites More sharing options...
KevinM1 Posted August 30, 2014 Share Posted August 30, 2014 That is the class name. It's its fully qualified name. Quote Link to comment https://forums.phpfreaks.com/topic/290755-get_classthis-with-namespaces/#findComment-1489403 Share on other sites More sharing options...
kicken Posted August 31, 2014 Share Posted August 31, 2014 (edited) You could use basename to extract just the last bit. Apparently that only works on windows. ltrim + strrchr could be used instead. $c = get_class($object); ltrim(strrchr($c, '\\'), '\\') Edited August 31, 2014 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/290755-get_classthis-with-namespaces/#findComment-1489436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.