PHP 7.2.0 Compatibility

163 views
Skip to first unread message

Darko

unread,
Dec 26, 2017, 2:36:31 PM12/26/17
to htmlpurifier
Hi, when I switch to PHP 7.2.0, a deprecated message is generated:

PHP Deprecated:  __autoload() is deprecated, use spl_autoload_register() instead in /htmlpurifier/HTMLPurifier.autoload.php on line 17

I have checked manually and spl_autoload_register() function does exist, but at line 17 __autoload is still used, which generates above 'warning'. Switching back to 7.1.x everything works without above message.

Do you have plans to fix this?
Thanks

P.S. Btw, official forum htmlpurifier.org/phorum/ seems inaccessible / down, so I have posted this here.

Keith Davis

unread,
Dec 26, 2017, 4:01:50 PM12/26/17
to htmlpurifier
That function is only called if it exists and if spl_autoload_register does not exist. The composer.json requirements for this library is PHP 5.2, so I assume that code is just there for backwards compatibility.

Now the fact that it attempted to load in PHP 7.2 seems like an issue. What version of HTMLPurifier are you using?

Also, I confirm that http://htmlpurifier.org/phorum/ is down.

Darko

unread,
Dec 26, 2017, 4:35:21 PM12/26/17
to htmlpurifier
Hi Keith, thanks for reply.

I have tested all recent versions, including latest available 4.9.3
If you take a closer look at file HTMLPurifier.autoload.php (virtually unchanged for several past versions):

if (function_exists('spl_autoload_register') && function_exists('spl_autoload_unregister')) {
    // We need unregister for our pre-registering functionality
    HTMLPurifier_Bootstrap::registerAutoload();
    if (function_exists('__autoload')) {     // <-- PROBLEM IS HERE
        // Be polite and ensure that userland autoload gets retained
        spl_autoload_register('__autoload');
    }
} elseif (!function_exists('__autoload')) {
    function __autoload($class)
    {
        return HTMLPurifier_Bootstrap::autoload($class);
    }
}

(see <-- PROBLEM IS HERE line above)

So, that's the issue. It still kind of checks for __autoload in the first if clause, which always returns false (tested in PHP 5.6, 7.1 and 7.2) and that is the problem -- function __autoload does not exists, so it always fallbacks to second clause.

Keith Davis

unread,
Dec 26, 2017, 4:47:29 PM12/26/17
to htmlpu...@googlegroups.com
From the docs, __autoload is only deprecated as of PHP 7.2:


Per the dev's notes, that additional call is to load __autoload after the \HTMLPurifier_Bootstrap::registerAutoload() is called.

Keith Davis
214-906-5183

--
You received this message because you are subscribed to the Google Groups "htmlpurifier" group.
To unsubscribe from this group and stop receiving emails from it, send an email to htmlpurifier+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Darko

unread,
Dec 26, 2017, 4:50:17 PM12/26/17
to htmlpurifier
Yes, I know -- hence this topic and the title :)

I know, but that't the line responsible for the warning...

Edward Z. Yang

unread,
Dec 27, 2017, 6:19:50 PM12/27/17
to Darko, htmlpurifier
We have an open issue for it here:
https://github.com/ezyang/htmlpurifier/issues/154

I've been busy, but I'll take a PR for it :)

Edward

Excerpts from Darko's message of 2017-12-26 13:50:16 -0800:
Reply all
Reply to author
Forward
0 new messages