RE: [PHP] Unexpected behaviuor with __CLASS__
| From: | Rick Fletcher | Date: | Thu, 17 Jun 2004 16:48:25 +0000 |
| Subject: | RE: [PHP] Unexpected behaviuor with __CLASS__ | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188503@lists.php.net to get a copy of this message | ||
> on RedHat with PHP 4.3.6 the following code produces 'test' -
> I'm expecting
> 'test2':
>
> class test {
> function printClass() {
> echo __CLASS__;
> }
> }
>
> class test2 extends test {
> }
>
> test2::printClass();
>
>
> I would like to get/echo the name of the class calling the
> method - in my case test2. Any ideas?
__CLASS__, and the other PHP "magic constants" are resolved at compile time.
The behavior you've experienced here is the correct one.
AFAIK there is no way to achieve your desired result without creating an
instance of test2 or overriding printClass() in test2.
Cheers,
Rick