虽然phpinfo()和php -m将其显示为已启用,但XMLWriter无法正常工作

I'm trying to use XMLWriter to write a basic mysql table into xml, however XMLWriter() always shows up as an 'undefined class' in my IDE or 'class not found' in laravel's debug mode, etc.

It was my understanding that XMLWriter was baseline with an install of php, and even my phpinfo() shows that my current install of php (7.1.23) has XMLWriter enabled, though I cannot use it. php -m also confirms this.

What kind of steps can I take to diagnose or resolve this? I've done the basics of uninstalling/reinstalling php, restarting apache, and even restarting my machine.

I'm fairly new to laravel/php so it's fairly possible that I've missed something obvious about the usage of XMLWriter itself. Can anyone offer some insight into how I can go about getting this working?

here is the code I'm using for reference

public function downloadXML($option)
{

    switch($option) {
        case 1: $list = Book::all()->toArray();break;
        case 2: $list = Book::get('title')->toArray();break;
        case 3: $list = Book::select('author')->groupBy('author')->get()->toArray();break;
    }

$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument();
$xml->startElement('booklist');
foreach($list as $book)
{
    $xml->startElement('data');
    $xml->writeAttribute('id', $book->id);
    $xml->writeAttribute('title', $book->title);
    $xml->writeAttribute('author', $book->author);
    $xml->endElement();
}
$xml->endElement();
$xml->endDocument();

$content = $xml->outputMemory();
$xml = null;

return response($content)->header('Content-Type', 'text/xml');
}

I created a package that would vastly simplify this for you: https://github.com/mtownsend5512/response-xml

You could do something like this:

public function downloadXML($option)
{
    switch($option) {
        case 1: $list = Book::all()->toArray();break;
        case 2: $list = Book::get('title')->toArray();break;
        case 3: $list = Book::select('author')->groupBy('author')->get()->toArray();break;
    }

    return response()->xml($list);
}

In the event that you want to modify the way your XML looks, I recommend you look into Laravel resources.