I am using PhpWord to create a document that contains comments. I can create the file successfully, but when I try to open it, Word reports that it contains unreadable content. Although Word will continue to open the file, and the comments appear to be in the correct places, I would still like to find an elegant solution that prevents Word from displaying the warning.
I renamed the .docx file to a .zip and found that the package contains 2 comments.xml files.

The two files are identical, except that one contains the id for the comments, and the other does not.


Below is the code. It works fine if I do not include the comments. Any suggestions?
<?php
ob_start(); // output buffering is turned on
require_once('bootstrap.php');
// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getCompatibility()->setOoxmlVersion(15);
// Adding an empty Section to the document...
$section1 = $phpWord->addSection();
// A comment
$comment = new \PhpOffice\PhpWord\Element\Comment('Authors name');
$comment->addText('Test comment', ['bold' => true]);
$phpWord->addComment($comment);
$textrun = $section1->addTextRun();
$textrun->addText('This ');
$text = $textrun->addText('is');
$text->setCommentRangeStart($comment);
$textrun->addText(' a test');
ob_clean();
$temp_file = tempnam(sys_get_temp_dir(), 'PHPWord');
\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
// Saving the document as OOXML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($temp_file);
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="duplicates.docx"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
readfile($temp_file);
file_get_contents($temp_file);
?>