Re: New exceptions mechanism
| From: | Adam Bregenzer | Date: | Tue, 03 Feb 2004 23:53:46 +0000 |
| Subject: | Re: New exceptions mechanism | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-7523@lists.php.net to get a copy of this message | ||
Stig,
On Tue, 2004-02-03 at 17:27, Stig S. Bakken wrote:
> Try __CLASS__.
Thank you for the reply. This does work for the class the method is
defined in, however unfortunately it's not a solution for classes that
inherit this method. Here's the sample code I used in my first post:
class Foo {
function getClassName() {
// ???
}
}
class Bar extends Foo {
}
echo Foo::getClassName(); // returns 'foo'
echo Bar::getClassName(); // returns 'bar'
The solution I have right now that is inheritable, though very kludgy is
this:
class Foo {
function someFunc($class_name) {
return $class_name;
}
}
class Bar extends Foo {
function someFunc($class_name = NULL) {
return parent::someFunc(isset($class_name) ? $class_name : __CLASS__);
}
}
This does work, but I have to have this stub function copied into every
class that inherits Foo, plus I have an extra parameter in there. Is
there no better way?
Thanks again,
Adam
--
Adam Bregenzer
adam@bregenzer.net
http://adam.bregenzer.net/