Replies: 1   Views: 427
Getwordcontents sends empty array
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by CourtiGo  · 14-12-2022 - 16:48


We have a problem since a last merge on git.

We have :


$docx = new CreateDocxFromTemplate($file);

$contents = $docx->getWordContents(['type' => 'all']);

But $contents is an empty array, whatever the $file contents. What can cause that ?

Thanks for answering.

Posted by admin  · 14-12-2022 - 17:11


We have done some tests and the getWordContents method is working correctly. If the error has appeared since a last merge on git, we recommend you check the changes done in the merge. Maybe some problem trying to read the DOCX template? although phpdocx throws an Exception or an error when trying to use a not valid DOCX as template; or an invalid query or empty contents in the main document?

Please run the following sample included in the package: examples/DocxPath/getWordContents/sample_1.php . If you run this sample using the default code or using the following query:

$referenceNode = array(
  'type' => 'all',

or the following query:

$referenceNode = array(
  'type' => '*',

the contents are returned correctly. Please run this sample using phpdocx standalone and using the PHP CLI mode to check the output. We have tested it using Windows, Linux and macOS with PHP 5.6, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1 and PHP 8.2, and in all cases the output is correct.

If you send a DOCX template sample to contact[at] we'll run the same code using it to check the output. Also please send the PHP version you are using.