Forum Moderators: coopster

Message Too Old, No Replies

I need class of an object or better design

function to return class of $this

         

shumboom

11:18 am on Oct 18, 2008 (gmt 0)

10+ Year Member



I have searched all over for this simple question but cannot find the answer. Also I am not sure if I am doing the right thing and maybe I should change my design. I have a function which needs to do something slightly different depending on its class

Class A{
function develop(){
...
if (class of $this=='B') { ...};
...
}

Class B extends Class A{

}

$obj=new B;
$obj->develop();

I think I have 3 choices here

1. Have two functions in each class with a slightly different code.
2. Get the parent of the class (as above) and code accordingly
3. Split the function into two. Retain develop in Class A, and it calls a function SpecialLine which is in both classes.(not sure how to ensure the right function is called)

Which is the best option and its solution and is there anoter way?
thanks,Shumit

tumr

7:18 pm on Oct 18, 2008 (gmt 0)

10+ Year Member



I believe this should answer your question: [us.php.net...]

See Example 3, in particular, for being able to both use, and modify, a parent class's function.