Page 1 of 1

getting classname of current class

Posted: Fri Feb 06, 2004 10:26 am
by brainbug
Hi,

i've just another problem concerning classes, inheritance and the '::'
Syntax. Take a look at the following example code:

Code: Select all

<pre>
<?php
        class MyClass extends MyParent{
                private $__arr = Array();

                public function __construct() {
                        $this->__arr("test");
                }
                
                public function __arr($var) {
                        array_push($this->__arr, $var);
                }
        }       
        
        class MyParent {
                public function getClassname() {
                        print("My classname: " . __class__ . "\n");
                        print("My classname: " . get_class($this) . "\n");
                }
        }
        
        $obj = new MyClass();
        // print_r($obj);
        
        MyClass::getClassname();
?>
</pre>
Corresponding output:

> My classname: MyParent
> My classname:


The problem is, that i want MyClass::getClassname() to return "MyClass"?!

Can anybody help me?

Thanks a lot.
vivi