iionly/elggx_fivestar

PHP Fatal error: Cannot redeclare file_get_html()

Closed this issue · 4 comments

If in my Elgg site I install another plugin that uses PHP Simple HTML DOM Parser library (for example "Webservices Pack" by ColdTrick), the page ends up in "PHP Fatal error: Cannot redeclare file_get_html()" in case I create a new comment.

The Elggx Fivestar plugin already checks if the function str_get_html() included in the Simple HTML DOM Parser lib is already declared and only registers the library if this function is not yet available. Though it checks and includes outside the init function. You could move the registering and loading of the library to the init function:

function elggx_fivestar_init() {
    if (!function_exists('str_get_html')) {
        include dirname(__FILE__) . "/lib/simple_html_dom.php";
        elgg_register_library("fivestar_simple_html_dom", dirname(__FILE__) . "/lib/simple_html_dom.php");
        elgg_load_library("fivestar_simple_html_dom");
    }

    elggx_fivestar_settings();

Maybe this helps to avoid loading both instances of the library. Problem seems to be that the Webservices plugin does not check if the library is already loaded in all cases but simply includes the library directly. As the path of the lib is a different one in the two plugin the include_once will load both regardless of them being the same.

Maybe it would help to fall back to the Webservices lib within Elggx Fivestar by simply using
'''php
elgg_load_library("simple_html_dom");

to load the lib already registed by the Webservices plugin.

If this doesn't help either, you would have to make adjustments within the code of the Webservices plugin yourself (that's beyong what I can help you with though - ask Coldtrick then).

@iionly thank you very much for your clear and helpful answer!

Just noticed I left the line

include dirname(__FILE__) . "/lib/simple_html_dom.php";

in the modified code. This line should not be included as the elgg_register_library() and elgg_load_library() calls already add the library in the Elgg-ish way.

Thanks! I'll make some tests and maybe I'll propose to you or to the Coldtrick team a patch.