WordPress.org

Ready to get started?Download WordPress

Forums

Using spl_autoload causes errors when I include wp-load.php (5 posts)

  1. aswitzer
    Member
    Posted 2 years ago #

    I am trying to show blog posts outside of my WP blog install folder on my website - something I have done numerous times before.

    I'm using the simple bit of PHP code:

    define('WP_USE_THEMES', false);
    include('wp-load.php');
    query_posts('showposts=1');

    However, with this website I have also been using the PHP5 feature of spl_autoload and it appears to be the cause of this error as soon as I attempt to include wp-load.php as shown above:

    Fatal error: Uncaught exception 'LogicException' with message 'Class Translation_Entry could not be loaded' in /mnt/domains/nobigdiffpool.com/html/blog/wp-includes/pomo/entry.php:10 Stack trace: #0 [internal function]: spl_autoload('Translation_Ent...')

    I've experimented with various things to try and fix this - namely adding to my include path for WP, but am completely stuck. Any ideas?

  2. tobiasbeuving
    Member
    Posted 2 years ago #

    Same here (only in wp-admin, in the frontend it works fine):

    Fatal error: Uncaught exception 'LogicException' with message 'Class WP_User_Search could not be loaded' in /domains/.../DEFAULT/wp-admin/includes/deprecated.php:291 Stack trace: #0 [internal function]: spl_autoload('WP_User_Search') #1 /domains/..../DEFAULT/wp-admin/includes/deprecated.php(291): class_exists('WP_User_Search') #2 /domains/.../DEFAULT/wp-admin/includes/admin.php(59): require_once('/domains/...') #3 /domains/.../DEFAULT/wp-admin/admin.php(64): require_once('/domains/...') #4 /domains/.../DEFAULT/wp-admin/index.php(10): require_once('/domains/...') #5 {main} thrown in /domains/.../DEFAULT/wp-admin/includes/deprecated.php on line 291

    I agree with Ketwaroo that wordpress should use spl_autoload:
    http://wordpress.org/support/topic/use-spl_autoload-to-load-classes?replies=1

    Did you get to find a way around this?

  3. tobiasbeuving
    Member
    Posted 2 years ago #

    @aswitzer: I managed to hack around it by editing wp-included/pomo/entry.php and changing the line into:

    if ( !isset($imlikewhatever)):/*!class_exists( 'Translation_Entry' ) ):*/

    Be aware, after the next WP update you'll have to find the lines that try to instantiate inline classes and change them again!

    Anyhow, now I can spl_autoload my custom classes!

  4. adaykin
    Member
    Posted 2 years ago #

    I got this error also. Thanks for the fix. Is this a relatively new bug? Almost every example I saw had the same code as in the first post.

  5. tobiasbeuving
    Member
    Posted 2 years ago #

    @Adaykin - it's not really a bug, the error only occurs when there's some custom code included that utilizes PHP's spl_autoload feature.

    This function was introduced in PHP 5.1.2 so yes - it's a relatively new problem.

    WordPress does not use spl_autoload - yet.

    I proposed it as an idea for a future release of wordpress. Once properly implemented these problems will disappear.

    Vote for the idea here:

    http://wordpress.org/extend/ideas/topic/use-phps-spl_autoload-to-only-load-the-necessary-wordpress-classes

Topic Closed

This topic has been closed to new replies.

About this Topic