Jump to content

Archived

This topic is now archived and is closed to further replies.

effigy

Attaching a "trigger" to an existing Class Method

Recommended Posts

Hey folks,

I've returned for now and I'm trying to get back to speed. Is it possible to attach a function (method) to an existing method of a class? More specifically, every time I call [!--fonto:Courier New--][span style=\"font-family:Courier New\"][!--/fonto--]mysqli->query[!--fontc--][/span][!--/fontc--], I'd like it to do its thing, [i]and[/i] more.

Thanks.

Share this post


Link to post
Share on other sites
You could extend the existing class

[code]class theClass {

        function do_something() {
            echo 'foo';
        }
}

class my_class extends theClass {

         function do_something() {

                   parent::do_something();

                   $this->do_something_else();

         }

         function do_something_else() {
              echo 'bar';
         }
}

$x = new my_class;
$x->do_something();    // ---> foobar[/code]

Share this post


Link to post
Share on other sites
Thanks Barand. I found this helpful as well:

[a href=\"http://www.zend.com/php5/articles/php5-mysqli2.php#Heading5\" target=\"_blank\"]http://www.zend.com/php5/articles/php5-mysqli2.php#Heading5[/a]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.