[wp-trac] [WordPress Trac] #13436: WordPress class_exists() conflicts with __autoload() and php_auto_prepend (was: Wordpress class_exists() conflicts with __autoload() and php_auto_prepend)

WordPress Trac noreply at wordpress.org
Sat Dec 21 21:06:00 UTC 2013


#13436: WordPress class_exists() conflicts with __autoload() and php_auto_prepend
-------------------------+------------------------------
 Reporter:  galbus       |       Owner:
     Type:  enhancement  |      Status:  reopened
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:  3.0
 Severity:  minor        |  Resolution:
 Keywords:  needs-patch  |
-------------------------+------------------------------
Changes (by SergeyBiryukov):

 * version:  3.1 => 3.0
 * milestone:   => Awaiting Review


Old description:

> == Issue ==
>
> Wordpress core (and many plugins) use class_exists().
>
> http://php.net/manual/en/function.class-exists.php
>
> When Wordpress is integrated with custom/third party applications that
> use php_auto_prepend and autoload() to include/require files based on the
> $class_name parameter this generates errors as class_exists() triggers
> the autoload() and the files cannot be found.
>
> == To reproduce ==
>
> Using php_auto_prepend specify a file to include before every page
> request that contains the following PHP code:
>
> {{{
> <?php
> function __autoload($class) {
>     include($class.'.php');
> }
> ?>
> }}}
>
> Visit any front-end or back-end Wordpress page.
>
> == Solution ==
>
> As there is no autoload() function defined in Wordpress core the
> class_exists() should implement the second class_exists() parameter:
>
> {{{
> <?php
> if (!class_exists('ExampleClass', false)) {
>     ...
> }
> ?>
> }}}
>
> This stops calls to __autoload() and would fix the errors seen when
> integrating Wordpress with apps that implement this.
>
> I have implemented this and tested it and Wordpress works fine, but I
> can't find out where the SVN repo is for Wordpress 3 Beta 2 (the SVN page
> on the site takes me to 2.x).
>
> If someone could supply a link for SVN CO of WP3 I can provide the patch.

New description:

 == Issue ==

 WordPress core (and many plugins) use `class_exists()`.

 http://php.net/manual/en/function.class-exists.php

 When WordPress is integrated with custom/third party applications that use
 `php_auto_prepend` and `autoload()` to include/require files based on the
 `$class_name` parameter this generates errors as `class_exists()` triggers
 the `autoload()` and the files cannot be found.

 == To reproduce ==

 Using php_auto_prepend specify a file to include before every page request
 that contains the following PHP code:

 {{{
 <?php
 function __autoload($class) {
     include($class.'.php');
 }
 ?>
 }}}

 Visit any front-end or back-end WordPress page.

 == Solution ==

 As there is no `autoload()` function defined in WordPress core the
 `class_exists()` should implement the second `class_exists()` parameter:

 {{{
 <?php
 if (!class_exists('ExampleClass', false)) {
     ...
 }
 ?>
 }}}

 This stops calls to `__autoload()` and would fix the errors seen when
 integrating WordPress with apps that implement this.

 I have implemented this and tested it and WordPress works fine, but I
 can't find out where the SVN repo is for WordPress 3 Beta 2 (the SVN page
 on the site takes me to 2.x).

 If someone could supply a link for SVN CO of WP3 I can provide the patch.

--

--
Ticket URL: <http://core.trac.wordpress.org/ticket/13436#comment:13>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list