“JHtmlBehavior::polyfill not found” Fatal Error on Joomla

A new client called us this morning and told us that the was seeing the following error on his website when he was visiting it:

An error has occurred. 500 JHtmlBehavior::polyfill not found

So, we visited his website in order to check what is going on, and, to our surprise, we didn’t see the error. We deleted the Joomla cache of the website and we asked the client to clear his browser cache and check the site again, but he still saw the problem. We starting suspecting that it was a propagation issue and that the client was seeing a different version of the site, but, after asking the client to ping his website, we realized that he was seeing the same website as us.

So, we dug into the Joomla code searching for the polyfill error – and we quickly discovered something very interesting in the file behavior.php which is located under the libraries/cms/html folder. It was these 3 lines:

// Include core and polyfill for browsers lower than IE 9.
static::polyfill('event', 'lt IE 9');

Aha! It seems that the polyfill library was only being loaded if the person was using an IE browser that is less than Internet Explorer 9 (the client was using IE 8), but, why was it generating the error when Joomla tried to load it?

Further digging revealed that the polyfill library in Joomla 3.7.2 and in earlier versions does not support PHP 7 – it only supports PHP 5.5 and PHP 5.6, and since the client was using PHP 7, he was seeing an error.

So, what was the solution to the problem?

The solution to the problem was quite easy, all the client had to do was to use a different browser (he went with Google Chrome), and the problem was solved!

But what if the client didn’t have the option to switch to another browser?

Well, in that scenario, the client had to comment out the following line from the aforementioned behavior.php:

static::polyfill('event', 'lt IE 9');

Although we have to say, that commenting the above line may have other implications (we haven’t tested it to confirm) – so, as usual, proceed at your own risk.

We hope that you found our post helpful. If you are still seeing “JHtmlBehavior::polyfill not found” error on your website even after switching to another browser, then please contact us. We will always find a solution, our rates are super affordable, and our work is super clean!

2 Responses to ““JHtmlBehavior::polyfill not found” Fatal Error on Joomla”
  1. Comment by Michael Babker — September 27, 2017 @ 5:51 pm

    There’s some incorrect advice here.

    Joomla ships several polyfill libraries and functions. For the PHP API, there are polyfill libraries to ensure PHP functions added in releases newer than Joomla’s minimum version can be used (this includes the password_compat, random_compat, and sodium_compat libraries).

    The error message here is pointing to a missing “polyfill” method in the “JHtmlBehavior” class. The method in that class is designed to conditionally load JavaScript polyfill files into the browser to use newer JavaScript features in older browsers.

    You would get this error message if the method is missing in the PHP class. Why would you get this message? Generally, the two leading possibilities are that an update did not complete successfully and the affected file wasn’t updated or there is an extension overloading this particular core class (which happens far too often) and requires an update to include the new method.

    There is zero reason to overload the JHtml classes as JHtml natively supports a way to register custom callback functions for method keys. So if you are an extension developer and you are reading this, and overload the core JHtml library, I highly suggest you read up on the JHtml::register() method and refactor your code to use it.

  2. Comment by Fadi — September 29, 2017 @ 4:42 am

    Hi Michael,

    Thanks for mentioning the JHtml::register() method! Hopefully extension developers will listen to you and use it.

    Now the polyfill library is only included when the browser is an IE browser with version less than 9 (it is obvious in this line of code: static::polyfill(‘event’, ‘lt IE 9’); ), and this is still the case in Joomla 3.8. Under the libraries/vendor/symphony/, there are 2 folders polyfill-php55 and polyfill-php56, the first will be loaded for PHP 5.5, and the second will be loaded for PHP 5.6. If you’re using PHP > 5.6, then none of these classes will be loaded, and you will have the above fatal error when using IE < 9. So, simply switching to another browser (Firefox or Chrome) will fix the problem.

Leave a comment