当变量应该是一个对象时,变量一直被误认为是一个布尔值

I keep having an issue where one of my variables, $xml, keeps being mistaken for a boolean when it should be returning an object.

I've tried changing $xml to $data... thinking maybe it was a naming issue.

I have also tried isolating the str() function but that is being recognized as string - which is correct.

I have also tried using gettype(simplexml_load_string(str()); which returns a bool as well.

Please let me know what I might be doing wrong:

    function str() {
        if(file_exists(__DIR__ . '/../' . $clientXML)) {
            return file_get_contents(__DIR__ . '/../' . $clientXML);
        } else {
            return file_get_contents(__DIR__ . '/../xml-skeleton.xml');
        }
    }

    $xml = simplexml_load_string(str());

    echo 'XML IS: ' . gettype($xml);

simplexml_load_string returns FALSE if its unable to parse the xml string. You can deal/check for the error like this:

<?php
libxml_use_internal_errors(true);
$sxe = simplexml_load_string("<?xml version='1.0'><broken><xml></broken>");
if ($sxe === false) {
    echo "Failed loading XML
";
    foreach(libxml_get_errors() as $error) {
        echo "\t", $error->message;
    }
}
?>

This is taken from: http://us3.php.net/manual/en/simplexml.examples-errors.php