Plugin library generages 100K warnings
-
The plugin uses the library ‘php-simple-html-dom-parser’ which calls ‘define’ without checking that the constant doesn’t already exist. When other plugins on the site use the same library, this generates hundreds of thousands of warning in the logs since it runs every time a page loads. The log warnings look like this (note – these are only the first few, a warning is generated for each call to ‘define’:
PHP Warning: Constant HDOM_TYPE_ELEMENT already defined in /wp-content/plugins/wp-retina-2x/vendor/kub-at/php-simple-html-dom-parser/src/KubAT/PhpSimple/lib/simple_html_dom.php on line 26; PHP Warning: Constant HDOM_TYPE_COMMENT already defined in /wp-content/plugins/wp-retina-2x/vendor/kub-at/php-simple-html-dom-parser/src/KubAT/PhpSimple/lib/simple_html_dom.php on line 27; PHP Warning: Constant HDOM_TYPE_TEXT already defined in /wp-content/plugins/wp-retina-2x/vendor/kub-at/php-simple-html-dom-parser/src/KubAT/PhpSimple/lib/simple_html_dom.php on line 28;Your plugin needs to use a version of the library that calls ‘defined’ first to check that the constant doesn’t already exist, or else use a namespace and load the library in the namespace.
Here is the same code with defined checked first. You could just replace the above lines with this:
defined('HDOM_TYPE_ELEMENT') || define('HDOM_TYPE_ELEMENT', 1);
defined('HDOM_TYPE_COMMENT') || define('HDOM_TYPE_COMMENT', 2);
defined('HDOM_TYPE_TEXT') || define('HDOM_TYPE_TEXT', 3);
defined('HDOM_TYPE_ENDTAG') || define('HDOM_TYPE_ENDTAG', 4);
defined('HDOM_TYPE_ROOT') || define('HDOM_TYPE_ROOT', 5);
defined('HDOM_TYPE_UNKNOWN') || define('HDOM_TYPE_UNKNOWN', 6);
defined('HDOM_QUOTE_DOUBLE') || define('HDOM_QUOTE_DOUBLE', 0);
defined('HDOM_QUOTE_SINGLE') || define('HDOM_QUOTE_SINGLE', 1);
defined('HDOM_QUOTE_NO') || define('HDOM_QUOTE_NO', 3);
defined('HDOM_INFO_BEGIN') || define('HDOM_INFO_BEGIN', 0);
defined('HDOM_INFO_END') || define('HDOM_INFO_END', 1);
defined('HDOM_INFO_QUOTE') || define('HDOM_INFO_QUOTE', 2);
defined('HDOM_INFO_SPACE') || define('HDOM_INFO_SPACE', 3);
defined('HDOM_INFO_TEXT') || define('HDOM_INFO_TEXT', 4);
defined('HDOM_INFO_INNER') || define('HDOM_INFO_INNER', 5);
defined('HDOM_INFO_OUTER') || define('HDOM_INFO_OUTER', 6);
defined('HDOM_INFO_ENDSPACE') || define('HDOM_INFO_ENDSPACE', 7);
defined('DEFAULT_TARGET_CHARSET') || define('DEFAULT_TARGET_CHARSET', 'UTF-8');
defined('DEFAULT_BR_TEXT') || define('DEFAULT_BR_TEXT', "\r\n");
defined('DEFAULT_SPAN_TEXT') || define('DEFAULT_SPAN_TEXT', ' ');
defined('MAX_FILE_SIZE') || define('MAX_FILE_SIZE', 600000);
defined('HDOM_SMARTY_AS_TEXT') || define('HDOM_SMARTY_AS_TEXT', 1);
The topic ‘Plugin library generages 100K warnings’ is closed to new replies.