|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-06-12 15:23 UTC] n dot scheer at binserv dot de
Description:
------------
We currently use an exception-handler that writes information about the exception to a xml file.
Recently we noticed, that sometimes the resulting xml file is just empty - without any error message being triggered.
I was able to reduce the code to the example below. There's no obvious reason why the script should not be able to write the xml content.
Interesting thing is: Throwing an exception manually does not trigger this behavior.
Test script:
---------------
<?php
@unlink( '/tmp/err.xml' );
function exception_handler( Throwable $exception )
{
echo "exception handler called\n";
$xw = new XMLWriter();
var_dump( $xw );
$xw->openURI( '/tmp/err.xml' );
$xw->startDocument( '1.0', 'UTF-8' );
$xw->startElement( 'error' );
$xw->endElement();
$returnValue = $xw->endDocument();
if ( $returnValue === false )
{
die( "unable to write error xml\n" );
}
die("error xml written\n");
} # function exception_handler(...)
set_exception_handler( 'exception_handler' );
new SoapClient( 'https://localhost/', [] );
#throw new Exception("dummy");
Expected result:
----------------
exception handler called
object(XMLWriter)#1 (0) {
}
error xml written
(/tmp/err.xml exists with content <?xml version="1.0" encoding="UTF-8"?>
<error/>)
Actual result:
--------------
exception handler called
object(XMLWriter)#1 (0) {
}
unable to write error xml
(/tmp/err.xml exists but is empty)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 02:00:01 2025 UTC |
Further testing shows, that registering an exception handler is not needed to trigger the behavior. In fact, it suffices to have a SoapFault-Exception thrown/catched - XMLWriter will refuse to write xml files afterwards. So the reproduction code can be narrowed down to: <?php @unlink( '/tmp/err.xml' ); try { new SoapClient( 'https://localhost/', [] ); } catch ( Throwable $e ) { echo "exception catched\n"; } $xw = new XMLWriter(); var_dump( $xw ); $xw->openURI( '/tmp/err.xml' ); $xw->startDocument( '1.0', 'UTF-8' ); $xw->startElement( 'error' ); $xw->endElement(); if ( $xw->endDocument() ) { echo "error xml written\n"; } else { echo "unable to write error xml\n"; }