Make WordPress Core

Opened 2 years ago

Last modified 3 months ago

#20523 new feature request

Disable autoloader when using class_exists()

Reported by: michael.heuberger Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3.1
Component: Bootstrap/Load Keywords:
Focuses: Cc:


A couple of files inside the /wp-includes/pomo directory use class_exists() the wrong way, for example in /wp-includes/pomo/entry.php :

if ( !class_exists( 'Translation_Entry') ):

It should be:

if ( !class_exists( 'Translation_Entry', false) ):

The second parameter 'false' disables autoloading. This is important because I'm integrating some WP functions into another existing website which already comes with an Autoloader for some classes = confusion.

This should be easy to fix. Thanks :)

Change History (3)

comment:1 kurtpayne2 years ago

  • Cc kpayne@… added
  • Type changed from defect (bug) to feature request

Can you add your own autoloader to the stack before you add WordPress to your existing codebase?

spl_autoload_register( function( $className ) {
  // If you're the last on the stack, the other autoloader should
  // take care of its own classes, but if it fails to find $className
  // you'll end up here, just don't throw an exception
} );

This might prevent the errors you're seeing.

You could also look at loading only the pieces of WordPress you need with SHORTINIT

comment:2 michael.heuberger2 years ago

Done, that works. But really, it's not cool and I'll remove that code once this bug has been fixed.

By the way, WordPress should come with an own bootstrapper to load only the pieces we need with SHORTINIT. Do not like the code there in that discussion forum. Shouldn't be like that.

comment:3 nacin3 months ago

  • Component changed from General to Bootstrap/Load
Note: See TracTickets for help on using tickets.