2014-03-07 34 views
-1

檢查活給出(在底部) - http://cchoco.net/2014/03/01/un-appareil-photo-dans-une-maison-hantee/警告:str_repeat()預計參數2要長,陣列中

錯誤 - 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"; 
} 
+1

告訴我們你在哪裏調用該函數,你似乎在傳遞一個數組作爲'$ depth'。 – CodeBird

+0

總是「$ depth」整數值嗎? – Girish

回答

1

$depth變量是當函數需要一個整數數組

檢查$depth變量 並避免坡平了,你這個錯誤可以改變

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

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

這種方式,如果一個數組傳遞它將只設置第二個參數爲1。

還可以測試所述$depth變量之前通過調用

$depth = is_array($depth) ? array_shift($depth) : $depth; 

或代替它傳遞給str_repeat功能的array_shift從該數組檢索所需的值,如果它不是數組的第一個指數...

+0

這將刪除PHP錯誤,但會破壞該函數。 – NateWr

+0

修改了包含數組檢查的答案 – zoranc

+0

它不應該中斷函數,因爲它將把這種情況視爲沒有深度通過(它會將其設置爲0),他已經在他的函數中作爲一個例子調用'!empty($ depth)? $ depth:0' bit – zoranc

0

正是它說 - $depth是一個數組。考慮使用intval($depth),並且還定義功能,像這樣:

function html($depth=0) 
+1

這隻會破壞功能。在數組上運行intval()只會返回0或1,而不是函數正常工作所需的深度值。 – NateWr

相關問題