Support » How-To and Troubleshooting » Using spl_autoload causes errors when I include wp-load.php

Using spl_autoload causes errors when I include wp-load.php

  • 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);

    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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:

    Did you get to find a way around this?

    @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!

    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.

    @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:


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using spl_autoload causes errors when I include wp-load.php’ is closed to new replies.