我將一個對象轉換爲數組,之後我無法通過鍵訪問得到的數組。將對象投射到數組 - 奇怪的行爲
這是代碼
print_r($new);
$new = (array)$new;
echo $new['EPPContactemail'];
foreach($new as $attr=>$value)
{
echo "$attr => $value \n";
}
並且輸出是
EPPContact Object
(
[id:EPPContact:private] => 6553377C74FC9899
[roid:EPPContact:private] => 50085436-UK
[status:EPPContact:private] => ok
[voice:EPPContact:private] => +44.554545454
[email:EPPContact:private] => [email protected]
[fax:EPPContact:private] =>
[clID:EPPContact:private] => TSOHOST
[crID:EPPContact:private] => EPP-TSOHOST
[crDate:EPPContact:private] => 2013-07-17T09:53:41
)
Notice: Undefined index: EPPContactemail in /home/parvhraban/domains/src/local_libs/EPP/Builder/Contact/Update.php on line 9
EPPContactid => 6553377C74FC9899
EPPContactroid => 50085436-UK
EPPContactstatus => ok
EPPContactvoice => +44.554545454
EPPContactemail => [email protected]
EPPContactfax =>
EPPContactclID => TSOHOST
EPPContactcrID => EPP-TSOHOST
EPPContactcrDate => 2013-07-17T09:53:41
我可以清楚地看到EPPContactemail鍵存在並保持訪問時(第3行,回波語句)雖然值它拋出未定義索引的錯誤。
你能解釋一下是什麼導致了這種行爲?
如果你改變了變量名稱仍然發生? –
@Tomás:它不是varname,它是鍵的類型:string!== binary_string –
[相關答案](http://stackoverflow.com/questions/14547187/what-is-a-integer-property-and -whats-的含義-的-0A-0A/14547243#14547243)。 –