Thanks David, I noticed the __LINE__ and __FUNCTION__ magic constants too, but they don't really contain the values I was looking for, as they have the current function and line in it. But what I want my Logging class (I have one too :D) to display is what I am about to illustrate with an example:
script: index.php ----------------- 01 $Database->connect('host', 'database', 'username', 'password'); (...) 20 $Database->execute('DELETE news WHERE id IN ()'); -> this would produce an error in my Database class, error in sql syntax script: class.database.inc.php ------------------------------ 2 class Database { 3 4 var $C; # Connection resource 5 var $S; # Settings 6 var $L; # Log Object 7 var $R; # Result 8 9 function Database($Host, $Database, $Username, $Password) { 10 global $Log; 11 12 $this->S = Array( 'host' => $Host, 13 'database' => $Database, 14 'username' => $Username, 15 'password' => $Password 16 ); 17 18 $this->L = $Log; 19 20 return true; 21 } (...) 55 function execute() { 56 $this->connect(false); 57 58 # Prepare 59 $Query = $this->prepare(func_get_args()); 60 $this->dblog($Query); 61 62 # Execute the query 63 $this->R['resource'] = @mysql_query($Query, $this->C) or $this->dberror(); 64 $this->R['affectedrows'] = @mysql_affected_rows($this->C) or $this->dberror(); 65 66 return $this->R['affectedrows']; 67 } (...) 171 function dberror() { 172 if ($String = mysql_error($this->C)) { 173 $OldType = $this->L->setLogType(L_STDOUT); 174 $this->L->Error('[database] '.$String); 175 $this->L->setLogType($OldType); 176 }; 177 } 178 }; I could fairly live with passing __LINE__ and __FUNCTION__ at some places, but not in my index.php (seperating front- and backend). What I want dberror() to pass to my logging module is something like "You have an error in your sql syntax at line 1, called from index.php on line 20". The first part being just the mysql error, after the comma from where the errorfull query was called .. Thanks once more, Wouter Ps. or am I really wanting too much now? -----Oorspronkelijk bericht----- Van: David Otton [mailto:[EMAIL PROTECTED] Verzonden: vrijdag 15 augustus 2003 16:13 Aan: Wouter van Vliet Onderwerp: Re: [PHP] Determining where a function is called from.. On Fri, 15 Aug 2003 16:02:24 +0200, you wrote: >I've got this problem .. not really a problem but still some thing to my >disliking. For a project I wrote some database handling class, no big deal. >When a function from this module is called with a query containing an error, >or some other error occurs inside this class it reports to my that an error >occured inside that class. "Line blabla of class.database.inc.php". But what >I really want to know is on what line the $Database->select() or such was >called so that I can effectively trace the error. > >So, for effective error reporting I would like to know if there are >functions or constants containing > - the script-name a user-function is called from > - the linenumber of this script a user-function is called from > > - And maybe it would even be doable to get an entire stack-trace of files >and lines and functions to the point an error (or any other thing I would >like to trace to) occurrs. It's just about possible, but you have to do it by hand. You need the __LINE__ and __FUNCTION__ magic constants. Eg function makeerror ($errorstring, $function, $line) { die ("Error: $errorstring on line $line in $function"); } makeerror("Can't connect to database", __FUNCTION__, __LINE__); I have a fairly standard way of handling errors in classes that I can discuss in more detail, if you want. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php