php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78150 Unable to use XMLWriter after a SoapFault-Exception
Submitted: 2019-06-12 15:23 UTC Modified: 2019-06-28 15:59 UTC
From: n dot scheer at binserv dot de Assigned:
Status: Verified Package: XML Writer
PHP Version: 7.3.6 OS: Centos 7.6 x64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-12 15:28 UTC] n dot scheer at binserv dot de
PHP 7.2.19 shows this behaviour as well
 [2019-06-28 09:19 UTC] n dot scheer at binserv dot de
-Summary: Unable to use XMLWriter in Exception-Handler +Summary: Unable to use XMLWriter after a SoapFault-Exception
 [2019-06-28 09:19 UTC] n dot scheer at binserv dot de
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";
}
 [2019-06-28 15:59 UTC] cmb@php.net
-Status: Open +Status: Verified
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 17:01:33 2019 UTC