• I’ve been struggling for months with a non-critical php error that’s been flooding my log files.
    Somehow a poorly(?) coded theme or plugin file (uncertain which one, but I suspect w3tc) is passing a variable to build_query_string with slips by the if ( !is_scalar($this->query_vars[$wpvar]) ) conditional and sends an array variable to the rawurlencode() on line 528 in class-wp.php, which isn’t allowed by php.
    This results in the error being logged frequently all/every day.

    I’ve found a “fix” by modified this core file to include the is_array() condition to the if:
    if ( ( !is_scalar($this->query_vars[$wpvar]) || is_array($this->query_vars[$wpvar]) ) )

    Result: no more errors and no noticeable problems/issues.

    I realize the problem is most likely the result of bad coding outside of the core. However, that if(!is_scalar()) conditional is not doing what it is intended to do by preventing bad code from creating a php error.

    Is there another way to filter the variable without changing core? Or, is there a way to get this small addendum put into core? Not sure if anyone else is having, or has ever had, this problem before.

    Thanks,
    Chad

    Here’s the source block of class-wp.php for reference:

    521	        public function build_query_string() {
    522	                $this->query_string = '';
    523	                foreach ( (array) array_keys($this->query_vars) as $wpvar) {
    524	                        if ( '' != $this->query_vars[$wpvar] ) {
    525	                                $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
    526	                                if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
    527	                                        continue;
    528	                                $this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
    529	                        }
    530	                }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘A core file php conditional not working as intended leading to errors.’ is closed to new replies.