Forum Moderators: coopster

Message Too Old, No Replies

PHP class methods

if( class is called from child)?

         

uckc

9:15 pm on Oct 24, 2009 (gmt 0)

10+ Year Member



Is there any built-in function or any way to check if a class method is called from parent class or child class?

Example:
class ParentClass {
__construct(...){
...
}
function ABC(...){
if(function called from child){
echo "called from child";
}else{
echo "called from parent";
}
}

class ChildClass {
__construct(...){
...
}
function CBA(...){
...
parent:ABC(...);
}

Thanks!

caraie

6:34 am on Oct 25, 2009 (gmt 0)

10+ Year Member



Hi, you tried something like this?, the child override the parent class, if you call the child you'll obtain "i'm the child" and if you call the parent "I'm the parent":

class ParentClass{
function ABC(){
echo ("I'm the parent");
}
}

class ChildClass extends ParentClass{
function ABC(){
echo ("I'm the child");
}
}