SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Dec 30, 2003, 22:52 #1
- Join Date
- Oct 2003
- Location
- Beijing
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Accessing variables from a function within a function
I have the following class:
Code:class ErrorLog { var $logFile = ""; function ErrorLog($fileName) { error_reporting(E_ALL); $this->logFile = $fileName; function handleError($type, $msg, $file, $line) { error_log("$msg", 3, $this->logFile); } set_error_handler('handleError'); } }
Anybody know what I am missing here?
Thanks for your help!
-
Dec 31, 2003, 00:01 #2
- Join Date
- Jul 2003
- Location
- Palo Alto
- Posts
- 179
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well... yeah. handleError() has no knowledge of ErrorLog or its members. Why is handleError() a sub of the constructor? Is there some reason you can't make it a class method?
I think there is a world market for maybe five computers.
- Thomas Watson, chairman of IBM, 1943.
-
Dec 31, 2003, 07:06 #3
I'm wondering why you would ever want to do this? (function in the function). I cant think of a good reason for doing this. Can you explain your reasoning for this? (and i'm not sure this is even good programming semantics (wd?) ) Thanks.
Erh
-
Dec 31, 2003, 07:59 #4
- Join Date
- Oct 2003
- Location
- Germany
- Posts
- 2,195
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
set_error_handler also accepts methods.
PHP Code:set_error_handler(array(&$this, 'handleError'));
-
Jan 5, 2004, 07:39 #5
- Join Date
- Oct 2003
- Location
- Beijing
- Posts
- 33
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Mandibal
Thanks for everyone's help!
-
Jan 5, 2004, 07:57 #6Off Topic:
Actually, I got this code directly from a user-contributed note on the PHP manual that seemed to make sense at the time.
PHP Code:Class Error {
* Function Error() {
** set_error_handler('HandleError');
* }
Function HandleError($n, $m, $f, $l){
** * print_r(debug_backtrace());
**}
}
Erh
Bookmarks