[PHP] __FILE__ and __LINE__ of calling scripts?
Hi, I want to find out if it is possible to get the file name and the line number of a calling script (__FILE__, __LINE_) from a calling class automatically. Let me explain: I have a db class which gets called in other classes. Now, when an sql error occurs I would like to find out which file and on which line it was. E.g.: [snip] class DB { function doQuery( $inq ) { ... if( !this_result ) { $this-drawError(**want the __FILE_ and __LINE__ of the calling script here** ..); ... } } } class Caller { function sql_doQuery() { $SQL-doQuery('SELECT me FROM WHERE id=0'); } } [/snip] The drawError function outputs the error report to the browser and halts the script (developer debug). Currently I get the __FILE__ and __LINE__ of the DB class, i.e. where the query error happened (as in doQuery()). Instead I would like to get something like caller.fileName, caller.lineNumber (pseudo code). Is that at all possible without having to pass the file name and the line number into the query function manually? Thanks Thomas SPIRAL EYE STUDIOS P.O. Box 37907, Faerie Glen, 0043 Tel: +27 12 362 3486 Fax: +27 12 362 3493 Mobile: +27 82 442 9228 Email: [EMAIL PROTECTED] Web: www.spiraleye.co.za -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] __FILE__ and __LINE__ of calling scripts?
I want to find out if it is possible to get the file name and the line number of a calling script (__FILE__, __LINE_) from a calling class automatically. debug_backtrace contains that info. http://www.php.net/debug_backtrace -- Scott Noyes [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] __FILE__ and __LINE__ of calling scripts?
Thomas wrote: Hi, I want to find out if it is possible to get the file name and the line number of a calling script (__FILE__, __LINE_) from a calling class automatically. Let me explain: I have a db class which gets called in other classes. Now, when an sql error occurs I would like to find out which file and on which line it was. E.g.: [snip] class DB { function doQuery( $inq ) { ... if( !this_result ) { $this-drawError(**want the __FILE_ and __LINE__ of the calling script here** ..); ... } } } class Caller { function sql_doQuery() { $SQL-doQuery('SELECT me FROM WHERE id=0'); } } [/snip] The drawError function outputs the error report to the browser and halts the script (developer debug). Currently I get the __FILE__ and __LINE__ of the DB class, i.e. where the query error happened (as in doQuery()). Instead I would like to get something like caller.fileName, caller.lineNumber (pseudo code). Is that at all possible without having to pass the file name and the line number into the query function manually? Thanks Thomas SPIRAL EYE STUDIOS P.O. Box 37907, Faerie Glen, 0043 Tel: +27 12 362 3486 Fax: +27 12 362 3493 Mobile: +27 82 442 9228 Email: [EMAIL PROTECTED] Web: www.spiraleye.co.za Have you tried looking up debug_backtrace() in the manual? HTH, Mikey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] __FILE__ and __LINE__ of calling scripts?
Thomas wrote: Hi, I want to find out if it is possible to get the file name and the line number of a calling script (__FILE__, __LINE_) from a calling class automatically. Let me explain: I have a db class which gets called in other classes. Now, when an sql error occurs I would like to find out which file and on which line it was. E.g.: [snip] class DB { function doQuery( $inq ) { ... if( !this_result ) { $this-drawError(**want the __FILE_ and __LINE__ of the calling script here** ..); ... } } } class Caller { function sql_doQuery() { $SQL-doQuery('SELECT me FROM WHERE id=0'); } } [/snip] The drawError function outputs the error report to the browser and halts the script (developer debug). Currently I get the __FILE__ and __LINE__ of the DB class, i.e. where the query error happened (as in doQuery()). Instead I would like to get something like caller.fileName, caller.lineNumber (pseudo code). Is that at all possible without having to pass the file name and the line number into the query function manually? Thanks Thomas SPIRAL EYE STUDIOS P.O. Box 37907, Faerie Glen, 0043 Tel: +27 12 362 3486 Fax: +27 12 362 3493 Mobile: +27 82 442 9228 Email: [EMAIL PROTECTED] Web: www.spiraleye.co.za How about having sql_doQuery() return false if it fails, then run drawError() from the calling script and you'd have the __FILE__ and __LINE__ there without doing a debug_backtrace() parse? Just a thought. Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] __FILE__ and __LINE__ of calling scripts?
Hi, I know I should not top post, but here it goes anyway: just wanted to say thanks and let others know that it is SOLVED. Cool thing this function! Gotta love PHP (thank heavens I don't need to use jsp right now ...) T -Original Message- From: Mikey [mailto:[EMAIL PROTECTED] Sent: 27 September 2005 03:20 PM To: php-general@lists.php.net Subject: Re: [PHP] __FILE__ and __LINE__ of calling scripts? Thomas wrote: Hi, I want to find out if it is possible to get the file name and the line number of a calling script (__FILE__, __LINE_) from a calling class automatically. Let me explain: I have a db class which gets called in other classes. Now, when an sql error occurs I would like to find out which file and on which line it was. E.g.: [snip] class DB { function doQuery( $inq ) { ... if( !this_result ) { $this-drawError(**want the __FILE_ and __LINE__ of thecalling script here** ..); ... } } } class Caller { function sql_doQuery() { $SQL-doQuery('SELECT me FROM WHERE id=0'); } } [/snip] The drawError function outputs the error report to the browser and halts the script (developer debug). Currently I get the __FILE__ and __LINE__ of the DB class, i.e. where the query error happened (as in doQuery()). Instead I would like to get something like caller.fileName, caller.lineNumber (pseudo code). Is that at all possible without having to pass the file name and the line number into the query function manually? Thanks Thomas SPIRAL EYE STUDIOS P.O. Box 37907, Faerie Glen, 0043 Tel: +27 12 362 3486 Fax: +27 12 362 3493 Mobile: +27 82 442 9228 Email: [EMAIL PROTECTED] Web: www.spiraleye.co.za Have you tried looking up debug_backtrace() in the manual? HTH, Mikey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php