doujichan1399
2015-02-17 05:03
浏览 49
已采纳

Wordpress PHP非法字符串错误

I am having some issues with a wordpress plugin (Customer Order CSV Export) that for some reason has started to put error warning into the exported file. It is saying there is an illegal string offset for every section of the order (so about 40 warnings for each file). I have only attached the warning for the order_number but the rest all say the same lines:

<b>Warning</b>:  Illegal string offset 'order_number' in <b>/home/.../wp-content/plugins/woocommerce-customer-order-csv-export/includes/class-wc-customer-order-csv-export-generator.php</b> on line <b>709</b><br />
<b>Warning</b>:  Illegal string offset 'order_number' in <b>/home/.../wp-content/plugins/woocommerce-customer-order-csv-export/includes/class-wc-customer-order-csv-export-generator.php</b> on line <b>713</b><br />
<b>Warning</b>:  Illegal string offset 'order_number' in <b>/home/.../wp-content/plugins/woocommerce-customer-order-csv-export/includes/class-wc-customer-order-csv-export-generator.php</b> on line <b>713</b><br />

The offending lines in the php file look like this:

private function write( $row ) {

    $data = array();

    foreach ( $this->headers as $header_key => $_ ) {

        if ( ! isset( $row[ $header_key ] ) ) {
            $row[ $header_key ] = '';
        }

        // strict string comparison, as values like '0' are valid
        $data[] = ( '' !== $row[ $header_key ] ) ? $row[ $header_key ] : '';
    }

    fputcsv( $this->stream, $data, $this->delimiter, $this->enclosure );
}

The error lines are 709:

$row[ $header_key ] = '';

and 713:

$data[] = ( '' !== $row[ $header_key ] ) ? $row[ $header_key ] : '';

Looking around at some similar questions, it looks like it is to do with isset: as in this answer and in this one. I'm not sure how to fix the code I have to make this work, or if that is indeed the actual problem and not something else.

The exported csv file contains all the warning messages each on a new line after each order.

Any help appreciated.

1条回答 默认 最新

相关推荐 更多相似问题