對不起,我找不到更好的寫法=/如何檢查對象屬性類型?
我收到一個名爲ErrorBase的錯誤對象。
如果只有一個錯誤,將返回我下面的:
public 'ErrorBase' =>
public 'CODIGO_ERRO' => string '1' (length=1)
public 'MENSAGEM_ERRO' => string 'Autenticação Inválida' (length=24)
public 'TIPO_ERRO' => string 'Usuario' (length=7)
但如果有不止一個錯誤,它會返回我的對象是這樣一個數組:
public 'ErrorBase' =>
array
0 =>
object(stdClass)[30]
public 'CODIGO_ERRO' => string '1' (length=1)
public 'MENSAGEM_ERRO' => string 'Autenticação Inválida' (length=24)
public 'TIPO_ERRO' => string 'Usuario' (length=7)
1 =>
object(stdClass)[31]
public 'CODIGO_ERRO' => string '002' (length=3)
public 'MENSAGEM_ERRO' => string 'teste 002' (length=9)
public 'TIPO_ERRO' => string 'tipo 002' (length=8)
2 =>
object(stdClass)[32]
public 'CODIGO_ERRO' => string '003' (length=3)
public 'MENSAGEM_ERRO' => string 'teste 003' (length=9)
public 'TIPO_ERRO' => string 'tipo 003' (length=8)
3 =>
object(stdClass)[33]
public 'CODIGO_ERRO' => string '004' (length=3)
public 'MENSAGEM_ERRO' => string 'teste 004' (length=9)
public 'TIPO_ERRO' => string 'tipo 004' (length=8)
我該如何處理這些情況? 如何檢查是否有一個對象數組或只有一個對象?
預先感謝任何幫助。
什麼是ErrorBase?你的僞代碼不是很清楚。 – 2011-05-23 13:57:48
只是一個類...這是返回的類 – Gerep 2011-05-23 14:03:27
的var_dump(),所以類ErrorBase也有一個名爲ErrorBase的屬性?在這種情況下'if(is_array($ instanceOfErrorBase-> ErrorBase)){/ * stuff * /}' – Hannes 2011-05-23 14:55:09