Home » Logging » Log » Bug #6831
Observer factory method include path is not correct
Details
| Submitted | 2006-02-18 23:49 UTC |
|---|---|
| From | peter at oncefuture dot com |
| Assigned | jon |
| Status | Closed |
| Package | Log |
| PHP Version | 4.4.2 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2006-02-18 23:49 UTC] peter at oncefuture dot com
Description:
------------
The following code from lines 75-82 of observer.php seems to
look for the existance of a file containing an observer sub
class in the same directory as it resides.
-----
/* Support both the new-style and old-style file naming
conventions. */
if (file_exists(dirname(__FILE__) . '/observer_' .
$type . '.php')) {
-----
However the code then goes one to set the include path for
the subclass equal a sub directory 'Log/'.
-----
$classfile = 'Log/observer_' . $type . '.php';
$newstyle = true;
} else {
$classfile = 'Log/' . $type . '.php';
$newstyle = false;
}
-----
This causes the observer object instantiation to fail.
removing the "Log/" fron lines 77 and 80 fixes the issue.
PATCHED FACTORY FUNCTION
-----
function &factory($type, $priority = PEAR_LOG_INFO, $conf =
array())
{
$type = strtolower($type);
$class = 'Log_observer_' . $type;
/* Support both the new-style and old-style file
naming conventions. */
if (file_exists(dirname(__FILE__) . '/observer_' .
$type . '.php')) {
$classfile = 'observer_' . $type . '.php';
$newstyle = true;
} else {
$classfile = $type . '.php';
$newstyle = false;
}
/* Issue a warning if the old-style conventions are
being used. */
if (!$newstyle)
{
trigger_error('Using old-style Log_observer
conventions',
E_USER_WARNING);
}
/*
* Attempt to include our version of the named
class, but don't treat
* a failure as fatal. The caller may have already
included their own
* version of the named class.
*/
@include_once $classfile;
/* If the class exists, return a new instance of it.
*/
if (class_exists($class)) {
/* Support both new-style and old-style
construction. */
if ($newstyle) {
$object =& new $class($priority, $conf);
} else {
$object =& new $class($priority);
}
return $object;
}
return null;
}
Test script:
---------------
Just remove the @ from include_once() on line 96 and you will see the problem.