来自simplexml_load_string的XML的var_dump

I have an XML object created by simplexml_load_string from the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<Website hasRead="true" hasWrite="true" key="managementui" terminalUserPin="" username="admin">
  <Section key="organisation">
    <Controller key="Sites">
      <Function hasRead="false" hasWrite="false" key="estateLayout"/>  
    </Controller>
  </Section>
  <Section hasRead="false" hasWrite="false" key="settings"/>
</Website>

The is stored in variable $xml

When I try:

$xmlkey = $xml['key'];
var_dump($xmlkey);

I expect to see the string 'managementui' but instead I get an exception. The error log isn't even showing anything. What's going on here?

Just trying to learn PHP after years of Java experience. When people say PHP is 'easy' it must be some strange usage of the word 'easy' I wasn't previously aware of :)

EDIT Having now extracted the troublesome bit of code into a smaller php file and running it from the command line, it seems there's nothing wrong. var_dump gives the expected result. Trouble is, it still throws an error in the production code. Is there any expected difference in behaviour between running on the commnad-line and on the web (on apache)?

Works for me.

Are you loading the xml as follows:

$string = '<?xml version="1.0" encoding="UTF-8"?>
<Website hasRead="true" hasWrite="true" key="managementui" terminalUserPin="" username="admin">
  <Section key="organisation">
    <Controller key="Sites">
      <Function hasRead="false" hasWrite="false" key="estateLayout"/>  
    </Controller>
  </Section>
  <Section hasRead="false" hasWrite="false" key="settings"/>
</Website>';

$xml = simplexml_load_string($string);

echo $xml['key']; // managementui