This question already has answers here: Array to Object and Object to Array in PHP - interesting behaviour (2 answers) Closed 7 years ago .

I am casting an object to array and after that I am unable to access the resulting array by a key.

This is the code

print_r($new); $new = (array)$new; echo $new['EPPContactemail']; foreach($new as $attr=>$value) { echo "$attr => $value

"; }

And the output is

EPPContact Object ( [id:EPPContact:private] => 6553377C74FC9899 [roid:EPPContact:private] => 50085436-UK [status:EPPContact:private] => ok [voice:EPPContact:private] => +44.554545454 [email:EPPContact:private] => some@email.com [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 => some@email.com EPPContactfax => EPPContactclID => TSOHOST EPPContactcrID => EPP-TSOHOST EPPContactcrDate => 2013-07-17T09:53:41

I can clearly see that EPPContactemail key exists and holds the value although when accessing it (line 3, echo statement) it throws an error of undefined index.

Could you please explain me what causes this behaviour?