警告:str_repeat()期望参数2为long,给定的数组为

时间:2014-03-07 11:04:01

标签: php wordpress

实时查看(在底部) - http://cchoco.net/2014/03/01/un-appareil-photo-dans-une-maison-hantee/

错误 - Warning: str_repeat() expects parameter 2 to be long, array given in /home3/philpaol/public_html/cchoco.net/wp-content/thesis/boxes/tl-custom-php/box.php on line 56

box.php页面的代码(第53行到第61行) -

public function html($depth) {
    global $thesis;

    $tab = str_repeat("\t", !empty($depth) ? $depth : 0);
    echo
        "$tab<div" . ($this->options[ 'id' ] ? ' id="' . trim( $thesis->api->esc( $this->options[ 'id' ] ) ) . '"' : '' ) . ' class="' . ( $this->options[ 'class' ] ? trim( $thesis->api->esc( $this->options[ 'class' ] ) ) : 'cus_code' ) . "\">\n" .
        "$tab\t" . trim( apply_filters( $this->_id, eval( '?>' . stripslashes( $this->options[ 'code' ] ) . '<?php ' ) ) ) . "\n" .
        "$tab</div>\n";
}

2 个答案:

答案 0 :(得分:1)

当函数期望整数

时,$depth变量是一个数组

检查$depth变量 并且为了避免弹出这个错误,你可以改变

str_repeat("\t", !empty($depth) ? $depth : 0)

str_repeat("\t", !empty($depth) && is_long($depth) ? $depth : 1)

这样,如果传递一个数组,它只会将第二个参数设置为1。

您还可以通过调用

$depth变量传递给str_repeat函数之前对其进行测试
$depth = is_array($depth) ? array_shift($depth) : $depth;

或代替array_shift从数组中检索所需的值,如果它不是该数组的第一个索引...

答案 1 :(得分:0)

正是它所说的 - $depth是一个数组。考虑使用intval($depth),并定义您的函数,如下所示:

function html($depth=0)