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: 2020-06-15 15:26 UTC
From: n dot scheer at binserv dot de Assigned: cmb (profile)
Status: Duplicate Package: XML Writer
PHP Version: 7.3.6 OS: Centos 7.6 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: n dot scheer at binserv dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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
 [2020-06-15 15:26 UTC] cmb@php.net
-Status: Verified +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2020-06-15 15:26 UTC] cmb@php.net
Closing as duplicate of bug #79191 (fixed as of PHP 7.3.15 and
7.4.3, respectively).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 02:01:29 2024 UTC