katzgrau/KLogger — Issue #7: KLogger fails if log handle is not a resource
Author: webbird
Created: 2011-12-19 09:33:14+00:00
State: open

I've encountered an error that occurs when fopen() does not return a valid file handle. The KLogger class never checks if the file handle is a valid _resource_.

In method __construct():
if (($this->_fileHandle = fopen($this->_logFilePath, 'a'))) {

This just checks if there's something returned by fopen(), not if it's a valid resource handle.

Same here (__destruct()):
if ($this->_fileHandle) {
fclose($this->_fileHandle);
}

Error message:
Warning: fclose(): 62 is not a valid stream resource in /path/to/KLogger.php on line XX

There should be an additional is_resource() check in __construct() to fix this.