php class extend - run something before running parent function

Posted by Patrick on Stack Overflow See other posts from Stack Overflow or by Patrick
Published on 2010-04-05T02:31:55Z Indexed on 2010/04/05 2:33 UTC
Read the original article Hit count: 272

Filed under:

Hi, say I have this class:

class animal {
   function noise() {
       print 'woof';
   }
   function move() {
       print 'moved';
   }
}

class dog extends animal {

}

What I would like to do is when i run $dog->noise() or $dog->move(), it would run something first prior to calling animal class's noise/move. Is this doable? Like maybe logging the function call. If not with class extend, what else can I use to achieve this?

Thank you!

© Stack Overflow or respective owner

Related posts about php