Home » Logging » Log » Bug #5182
Return new instance without including the handler class
Details
| Request #5182 | Return new instance without including the handler class |
|---|---|
| Submitted | 2005-08-23 10:58 UTC |
| From | o dot persson at gmail dot com |
| Assigned | jon |
| Status | Closed |
| Package | Log |
| PHP Version | 5.0.4 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-08-23 10:58 UTC] o dot persson at gmail dot com
Description:
------------
I believe it's unnecessary to try include the $classfile before checking if the class already exists. For internal handlers it makes sense since these will always be included by this function -- but not for custom handlers.
Using a custom handler which you've manually already loaded into memory, this function will try to load the file Log/handler.php.
This patch doesn't change anything more than this. What I'd also rather see is the check for the class_exists removed below this. Isn't it a fatal error if the log handler can't be loaded?
Test script:
---------------
Index: ../components/PEAR/Log.php
===================================================================
--- ../components/PEAR/Log.php (revision 23)
+++ ../components/PEAR/Log.php (working copy)
@@ -117,9 +117,16 @@
$classfile = 'Log/' . $handler . '.php';
/*
+ * The caller may have already included their own version of the named
+ * class. Check first if the class exists.
+ */
+ if (class_exists($class)) {
+ return new $class($name, $ident, $conf, $level);
+ }
+
+ /*
* 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.
+ * a failure as fatal.
*/
@include_once $classfile;