|
Posted by Torsten Roehr on 10/03/50 11:05
> Torsten, I also found the following link to be helpful. Check out the
> user notes from michael at digitalgnosis dot removethis dot com (he did
> something similar to what I have already suggested, i.e. call_user_func)
>
> http://www.php.net/manual/en/language.oop5.static.php
Hi Jason,
thanks for the link. It helped me to find out that this does work:
class Car {
function drive() {
echo '<pre>';print_r(debug_backtrace());
}
}
class Porsche extends Car {
function drive() {
parent::drive();
}
}
By "tunnelling" the call through Porsche's own drive() method
debug_backtrace() will contain two traces, one of them with the correct
class name.
I tried using reflection but "reflecting" car by using __CLASS__ doesn't
give any information about the classes that extend it. So this doesn't work
either.
Rory's proposed way of reading in the file contents and preg_matching the
method name works, but it's very, very ugly, indeed! ;)
Isn't it somewhat ridiculous that there is no *easy* way in PHP5 to achieve
what I consider to be a pretty straightforward requirement?:
"Get name of the class that invoked a static call of an inherited method"
I would like to thank all of those that cared about my problem and tried to
find a solution by providing a wide variety of ideas. Thank you very much!!!
Do you think it would be wise to ask for help on php-dev?
Best regards, Torsten
Navigation:
[Reply to this message]
|