[Plugin: WP Memcached Manager] Fix for fatal error in View Data (1 post)

  1. kitchin
    Posted 3 years ago #

    Thanks for this very nice plugin. Here is a fix for a fatal error that can hit the View Data feature.

    PHP has the terrible flaw of throwing fatal errors when (string) is used to cast objects. The esc_* functions in wp-includes/formatting.php do not guard against it. There are actually two types of objects to contend with, so I wrote a drop-in replacement for esc_attr().

    These are the errors, if the data happens to have objects:

    Catchable fatal error: Object of class stdClass could not be converted to string in ...wp-includes/formatting.php on line 466
    Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in in ...wp-includes/formatting.php on line 466

    ( The callstack is $string= (string)$string in wp_check_invalid_utf8() called by esc_attr() ).

    And is_object() cannot detect the second type! From http://php.net/is_object :

    This function will return FALSE if used on an unserialized object where the class definition is not present (even though gettype() returns object).

    Here is the fix.

    if (!function_exists('wpmm_esc_attr')) :
    function wpmm_esc_attr($text) {
      // Drop-in replacement for esc_attr().
      if (is_object($text)) return 'Object'; // otherwise (string)$text can generate fatal error!
      if (gettype($text)=='object') return 'Object-unserialzed'; // same, not detected by is_object()!
      return esc_attr($text);

    It can be added to wp-memcached-manager.php, and then change the 4 esc_arr() calls to wpmm_esc_attr().

    Or you could do it the try/catch way, since WP3.2 requires PHP5.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by kitchin
  • This topic is not a support question
  • WordPress version: 3.3.1