Jump to content


Photo

Attaching a "trigger" to an existing Class Method


  • Please log in to reply
2 replies to this topic

#1 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 12 June 2006 - 02:36 PM

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, and more.

Thanks.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 12 June 2006 - 06:20 PM

You could extend the existing class

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 12 June 2006 - 07:17 PM

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]
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users