You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by "James Brown (JIRA)" <ji...@apache.org> on 2010/11/11 04:52:13 UTC

[jira] Created: (LOG4PHP-129) Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

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

                 Key: LOG4PHP-129
                 URL: https://issues.apache.org/jira/browse/LOG4PHP-129
             Project: Log4php
          Issue Type: Bug
          Components: Code
    Affects Versions: 2.0
         Environment: Ubuntu & Apache
            Reporter: James Brown


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.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] [Commented] (LOG4PHP-129) Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

Posted by "James Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13037434#comment-13037434 ] 

James Brown commented on LOG4PHP-129:
-------------------------------------

The problem is that, just like Log4PHP, I don't have control of the source for the other modules in the project.  If each library provider takes the same approach as you ("it's not my problem, change your other code") then none of them will work together.

If you think that something suggested in the core PHP documentation is 'hackish' then I suppose that's your right.  It doesn't seem like a hack at all to me.  You are properly recognizing and dealing with code that will cause a problem when interacting with your code.  Another solution would be to report a fatal error when you detect the condition.  As I said, the main issue is that the problem will manifest in an odd and non-obvious way.

Thanks,

- James




> Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4PHP-129
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-129
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.0
>         Environment: Ubuntu & Apache
>            Reporter: James Brown
>             Fix For: 2.1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] Updated: (LOG4PHP-129) Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

Posted by "Christian Grobmeier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-129?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christian Grobmeier updated LOG4PHP-129:
----------------------------------------

    Fix Version/s: 2.1

> Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4PHP-129
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-129
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.0
>         Environment: Ubuntu & Apache
>            Reporter: James Brown
>             Fix For: 2.1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] [Commented] (LOG4PHP-129) Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13037545#comment-13037545 ] 

Ivan Habunek commented on LOG4PHP-129:
--------------------------------------

I was just writing the same argument. I also agree that we may produce a warning (I would not go for a fatal error) if an __autoload function is detected. That would tell the user explicitely what the problem is.

> Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4PHP-129
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-129
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.0
>         Environment: Ubuntu & Apache
>            Reporter: James Brown
>             Fix For: 2.1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LOG4PHP-129) Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13037290#comment-13037290 ] 

Ivan Habunek commented on LOG4PHP-129:
--------------------------------------

Your proposed fix seems a little bit hackish, I would rather not implement it in the log4php code. Wouldn't it be easier for you to use spl_autoload_register() in your project? That way you just add your autoload method onto the autoload stack and other projects will not override it.

I agree that we can put in a notice in the documentation somewhere. Maybe even create a FAQ page.

> Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4PHP-129
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-129
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.0
>         Environment: Ubuntu & Apache
>            Reporter: James Brown
>             Fix For: 2.1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (LOG4PHP-129) Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

Posted by "Ivan Habunek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4PHP-129?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ivan Habunek resolved LOG4PHP-129.
----------------------------------

    Resolution: Fixed

Added a warning in r1128568.
Created a new issue for creating a FAQ page: LOG4PHP-139

> Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4PHP-129
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-129
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.0
>         Environment: Ubuntu & Apache
>            Reporter: James Brown
>             Fix For: 2.1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (LOG4PHP-129) Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function

Posted by "Moritz Schmidt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4PHP-129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13037543#comment-13037543 ] 

Moritz Schmidt commented on LOG4PHP-129:
----------------------------------------

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


Only a partial fix. There'd still be a problem if someone inlcudes log4php (or _any_ other library using spl_autoload_register) first, and only then includes the one library that defines and uses __autoload .

Seriously: 
Code that still uses __autoload essentially breaks autoloading for every other module. 

spl_autoload_register has been around for long enough now, I wouldnt consider trying to fix other lib's bad behaviour. A FAQ entry may be appropriate..

> Log4PHP causes odd errors in the underlying application if used with source having an existing __autoload function
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4PHP-129
>                 URL: https://issues.apache.org/jira/browse/LOG4PHP-129
>             Project: Log4php
>          Issue Type: Bug
>          Components: Code
>    Affects Versions: 2.0
>         Environment: Ubuntu & Apache
>            Reporter: James Brown
>             Fix For: 2.1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira