Something I noticed during development today is that PHPDocX will not accept a numeric value when using addTemplateVariable. I discovered this while automatically calculating a total cost including tax when given a cost and a tax multiplier -- when using something like:
$docx->addTemplateVariable('totalincvat', $total * $vatrate);
PHPDocX ignores this and leaves the variable in place (showing $totalincvat$ in the document, for example). A wordaround would be:
$docx->addTemplateVariable('totalincvat', (string)($total * $vatrate));
Hopefully this helps someone.