Uploaded image for project: 'Log4php'
  1. Log4php
  2. LOG4PHP-129

Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.1.0
    • Code
    • None
    • Ubuntu & Apache

    Description

      According to the PHP documentation (see http://us.php.net/manual/en/function.spl-autoload-register.php): "If your code has an existing __autoload function then this function must be explicitly registered on the __autoload stack. This is because spl_autoload_register() will effectively replace the engine cache for the __autoload function by either spl_autoload() or spl_autoload_call()."

      I was attempting to introduce Log4PHP into an existing project that already had an __autoload function defined. As soon as I included Logger.php, I started getting errors from other components. These were confusing at first because the error was "Class 'Smarty' not found in ...". It turns out this was due to the previous __autoload function being overwritten by the call to spl_autoload_register in Logger.PHP.

      I suggest a simple fix. Add the following two lines to Logger.php around line 31 (just before the call to spl_autoload_register(array('Logger', 'autoload')). That fixed the problem in my particular application.

      if (function_exists('__autoload'))
      spl_autoload_register('__autoload');

      At the very least, this is an easy fix for anyone having this problem w/ Log4PHP. They can simply put these lines just prior to the require of Logger.php and it will fix the problem. If Log4PHP is not going to include this code, please at least put a note in the documentation so that people using Log4PHP know what they need to do to solve the problem.

      Attachments

        Activity

          People

            Unassigned Unassigned
            james.brown James Brown
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 4h
                4h
                Remaining:
                Remaining Estimate - 4h
                4h
                Logged:
                Time Spent - Not Specified
                Not Specified