The following error occurs with PHP 7.1 and the latest dompdf package through Composer:
DOMXPath::query(): Invalid expression
It does _not_ occur with PHP 7.0 or 5.6.
This is the stack trace:
#0 [internal function]: my_exception_error_handler(2, 'DOMXPath::query...', 'MyWebsite/...', 882, Array)
#1 MyWebsite/vendor/dompdf/dompdf/src/Css/Stylesheet.php(882): DOMXPath->query('//[@href]')
#2 MyWebsite/vendor/dompdf/dompdf/src/Dompdf.php(732): Dompdf\Css\Stylesheet->apply_styles(Object(Dompdf\Frame\FrameTree))
#3 MyWebsite/GeneratePdfInvoiceController.inc.php(117): Dompdf\Dompdf->render()
#4 MyWebsite/GeneratePdfInvoiceController.inc.php(63): GeneratePdfInvoiceController->doGeneratePdf('<!DOCTYPE html>...')
From the stack trace, it _seems_ that DOMXPath->query('//[@href]') generates the error.
My question:
Any chance to fix this by myself oder does it require an update to dompdf?
If the stack trace is correct, the following XPath query is the erroneous one:
//[@href]
If I'm right, this actually _is_ an invalid XPath syntax.
Probably it is meant to be written as
//*[@href]
The origin of this call seems to come from this source code line.
A minimal example that generates the error on my platform (Windows 10, IIS Express, PHP 7.1.1) is:
$dompdf = new Dompdf\Dompdf();
$dompdf->loadHtml("<!DOCTYPE html><html><body></body></html>");
$dompdf->render(); // โ This line throws.
Which version of dompdf are you using? We released changes in dompdf 0.8.0 to improve PHP 7.1 compatibility. Specifically, we addressed the invalid expression in #1329 and the non-numeric value issue in #1272.
The composer.json says "0.7-dev".
Being a bit of a PHP noob, I tried to upgrade but it says no new version available.
Am I doing something completely wrong?
(I'm using PHP Tools for Visual Studio)
Awesome! I've just uninstalled and reinstalled, now I'm on 0.8.0 and the issue is gone!
Most helpful comment
Awesome! I've just uninstalled and reinstalled, now I'm on 0.8.0 and the issue is gone!