freelanceprogrammers.org Forum Index » PHP

Get_class without $this


View user's profile Post To page top
derekscruggs Posted: Tue Apr 05, 2005 9:26 pm


Joined: 05 Apr 2005

Posts: 11
Get_class without $this
Within a class prototype, is there an alternative to get_class in the case
where you`re not actually insanticating the class?

For example, in the two classes below, I`d like to be able to
programatically know which class is being used via something like
get_class($this), but since the class isn`t instanciated, $this is null.

<?php
class A{
var $a;

function my_method() {
echo `<P>I am a::my_method()</P>`;
}
}

class B extends A{
var $b;
}

B::my_method(); //outputs "I am a::my_method"
?>

The B prototype is "smart" enough to inherit my_method from A. Is there a
way within my_method to figure out which class invoked it? If
get_class($this) worked, I could do something like this in A:

function my_method() {
echo `<P>I am ` . get_class($this) . `::my_method()</P>`;
}


...which would result in "I am b:my_method: in the example above.

BTW I`m working in PHP4.3

-Derek
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help