2014-01-25 24 views
0

我有這樣的代碼:我該如何解決這個錯誤:llegal字符串偏移'文本'?

if(strlen($userdata->yim['text']) > 2 && !isset($_POST['step1'])){ 

    $GLOBALS['error']  = 1; 
    $GLOBALS['error_type'] = "tip"; 
    $GLOBALS['error_msg'] = $userdata->yim['text'];} 

我讀到這個網站這個錯誤,但我不IDEEA如何應用在我的特殊代碼的修補程序。如果我重新發布問題,我很抱歉。

+0

謝謝你的提示答案,但正如我所說的,我不知道如何要做到這一點。我的開發人員給我留下了一些錯誤來解決問題,我不知道我在做什麼。 –

+0

它是什麼?是「if」語句還是最後一行? – putvande

+0

這是代碼行91. –

回答

0

嘗試做:var_dump($userdata->yim);來驗證yim確實存在並且包含關鍵字'text'。

甚至只是var_dump($userdata);

+0

使用var_dump($ userdata);但它仍然顯示錯誤。 –

+0

就在執行'if'測試的行之前,嘗試執行var_dump,緊接着'die;'將$ userdata的內容輸出到屏幕以進行調試。 –

+0

試過了,沒有變化。相同的結果。我可能會做錯了嗎? –

0

$userdata->yim['text']沒有設置,所以你應該檢查該第一:

if(isset($userdata->yim['text']) && strlen($userdata->yim['text']) > 2 && !isset($_POST['step1'])){ 

但是,如果代碼部分依賴於價值的東西是在這之前與錯這隻會隱藏這個問題。

+0

這工作。它確實隱藏了錯誤,但正如你所預料的那樣,問題依然存在。 –

0

爲了調試這一點,你將需要利用print_r(),這樣就可以看到你的對象或數組的內容:

// see what $userdata contains - update your question with the results of the line below 
echo '<div style="background-color:white; padding:15px;"><pre>'.print_r($userdata, true).'</pre></div>'; 

// see what $userdata->yim contains - update your question with the results of the line below as well 
echo '<div style="background-color:white; padding:15px;"><pre>'.print_r($userdata->yim, true).'</pre></div>'; 

if(strlen($userdata->yim['text']) > 2 && !isset($_POST['step1'])) 
{ 
    $GLOBALS['error']  = 1; 
    $GLOBALS['error_type'] = "tip"; 
    $GLOBALS['error_msg'] = $userdata->yim['text']; 
} 
相關問題