This line works:
$catXML->asXML('content/catalogue.xml');
The catalogue is saved correctly. The manual says asXML() should return a boolean TRUE or, on failure, FALSE. So I've tried:
if (!$catXML) {
// Catalogue did not save or path was invalid
$responseHd = 'Sorry';
etc....
But this reports success even when I set an invalid path. Also gettype($catXML) shows 'object' with both an invalid path and on success via valid path.
What am I missing?
You're not looking at the result of the asXML
call. You're just evaulating $catXML
, which is the SimpleXML object itself. This won't be affected by the call, it's still the same object it was beforehand.
If you want to check if the file was written successfully you need to assign the result of the call to something:
$success = $catXML->asXML('content/catalogue.xml');
if (!$success) {
// Catalogue did not save or path was invalid
$responseHd = 'Sorry';
...