Forum


Replies: 2   Views: 2669
Catch replacevariablebytext internal warning when variable does not exists
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 FGI  · 13-10-2017 - 07:45

Hello,

how can I intercept the warning generated by replaceVariableByText() when I try to replace a variable in the doc which does not exists?

Even if I surround with a try/catch, I still have the warning on stdout, and can't intercept it:

try {

    $docx->replaceVariableByText(['inexistant'=>'...']);

} catch (Exception $e) {

    echo $e->getMessage();

}
Warning: DOMDocument::loadXML(): ParsePI: PI xml0version space expected in Entity, line: 1 in vendor\phpdocx\classes\CreateDocxFromTemplate.inc on line 1943

Call Stack:
    ...
    0.3291   18337616   5. CreateDocxFromTemplate->replaceVariableByText() myclass.class.php:4912
    0.3291   18526032   6. CreateDocxFromTemplate->variable2Text() vendor\phpdocx\classes\CreateDocxFromTemplate.inc:1338
    0.3291   18526032   7. CreateDocxFromTemplate->repairVariables() vendor\phpdocx\classes\CreateDocxFromTemplate.inc:2085
    0.3310   18893696   8. DOMDocument->loadXML() vendor\phpdocx\classes\CreateDocxFromTemplate.inc:1943

Must I replace the logger by a custom behavior which throws exceptions, or something?

(Or is it a bug, as we should never have API internals warnings displayed?)

 

Best regards,