Re: Overriding core functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some already good workarounds given for this question...
BUT.
Is it even possible to override a core function?
Like I wrote a function called 'exit' and I got a parser error, which leads me to believe it is not even possible to override the core functions. Is this true of ALL PHP functions?
-B

Alex Turner wrote:
It may be possible to override the core function - I don't actually know. If you just define a new function with the same function it might
work OK.

The snag I see coming at you like a tonne of bricks is 'how do you call the original function once you have overridden it.'. This like like calling SUPER. in Java.

AJ

Peter Lauri wrote:
Yes, that could solve it. However, my question was if I can override the
core functions :) Similar that I can do Parent::myFunction() in a subclass,
I want to do that, but with core functions :)

-----Original Message-----
From: Jochem Maas [mailto:jochem@xxxxxxxxxxxxx] Sent: Tuesday, August 22, 2006 7:27 PM
To: Peter Lauri
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Overriding core functions

Peter Lauri wrote:
Hi,

I want to add some functionality when calling the mysql_query():


function my_query($Query) {

             //do stuff before

             mysql_query($Query);

             //do things after

}

// or something like:

class PeteDB {
   var $conn;

   function PeteDB($db, $usr, $pwd, $etc) {
    $this->conn = mysql_connect($db, $usr, $pwd, $etc);
    if (!is_resource($this->conn)) die('db is useless'); //
trigger_error()
   }

   function query($qry/*, $args*/) {
    // do stuff
    $r = mysql_query($qry, $this->conn);
    // do more stuff
    return $r;
   }
}

/*
tada!

hint: always use some kind of wrapper for things like db related functions
(because it allows for stuff like this and, for instance, makes it alot
easier to
switch dbs - because you only have to change code in one place, not counting
any db-specific
sql floating around your app)
*/

This would just be for one project where I want to record all Queries and
the result of them, creating an own logging function.
I did a lot of Google, but no article that I found that take care of this
subject.

/Peter




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux