Re: [PHP] get classname without namespace
On Sat, May 29, 2010 at 4:20 PM, Tanel Tammik keevit...@gmail.com wrote: Hi, is there a way to get the called classname without the namespace? ?php //PHP 5.3.x namespace some\where; abstract class ParentClass { public static function name() { return strtolower(get_called_class()); } public static function get_name() { echo 'name: ' . static::name(); } } class ChildClass extends ParentClass { } ChildClass::get_name(); ? the result i need: childclass the result i get: some\where\childclass also is it possible to get the name() into the static variable if only static method is called? Br Tanel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php $childclass = end(explode('\', $class_name_with_ns)); also is it possible to get the name() into the static variable if only static method is called? Not sure I understand this part. Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] get classname without namespace
Adam Richardson simples...@gmail.com wrote in message news:aanlktin0wqqlgwgm2lowcdv4i0c6bzsbfxhjwxv_j...@mail.gmail.com... On Sat, May 29, 2010 at 4:20 PM, Tanel Tammik keevit...@gmail.com wrote: Hi, is there a way to get the called classname without the namespace? ?php //PHP 5.3.x namespace some\where; abstract class ParentClass { public static function name() { return strtolower(get_called_class()); } public static function get_name() { echo 'name: ' . static::name(); } } class ChildClass extends ParentClass { } ChildClass::get_name(); ? the result i need: childclass the result i get: some\where\childclass also is it possible to get the name() into the static variable if only static method is called? Br Tanel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php $childclass = end(explode('\', $class_name_with_ns)); also is it possible to get the name() into the static variable if only static method is called? Not sure I understand this part. Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com yes, the static method is called and it's not possible... basicalli i'm making dynamic class for database manipulation where the child classname == tablename i just thought it would be not good to each time call name() as a method when tablename is need for sql query! Br Tanel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] get classname without namespace
On Sun, May 30, 2010 at 1:50 AM, Tanel Tammik keevit...@gmail.com wrote: Hi, is there a way to get the called classname without the namespace? ?php //PHP 5.3.x namespace some\where; abstract class ParentClass { public static function name() { return strtolower(get_called_class()); } public static function get_name() { echo 'name: ' . static::name(); } } class ChildClass extends ParentClass { } ChildClass::get_name(); ? the result i need: childclass the result i get: some\where\childclass also is it possible to get the name() into the static variable if only static method is called? Br Tanel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You need to extract that using strrpos and substr $name = substr($fullname_with_namespace, strrpos($fullname_with_namespace, '/')); -- Nilesh Govindarajan Facebook: nilesh.gr Twitter: nileshgr Website: www.itech7.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php