|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71595 NS end handler is never called
Submitted: 2016-02-15 02:38 UTC Modified: 2017-06-21 08:34 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: anrdaemon at freemail dot ru Assigned:
Status: Closed Package: XML related
PHP Version: 5.6.18 OS: Windows
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: anrdaemon at freemail dot ru
New email:
PHP Version: OS:


 [2016-02-15 02:38 UTC] anrdaemon at freemail dot ru
When NS-aware parser is created, the handler set by xml_set_end_namespace_decl_handler() is never called.

Test script:
$indent = '';
$parser = xml_parser_create_ns('UTF-8');

xml_set_end_namespace_decl_handler($parser, function($self, $name)
    global $indent;
    $ns = $name ?: '(default)';
    print $indent . "/NS:{$ns}\n";

// Expecting at least one mention of /NS: ...
xml_parse($parser, '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE shape PUBLIC "-//Dia//DTD Dia shape 1.0//EN" "">
  <svg xmlns:svg="" svg:width="300px" svg:height="300px" svg:viewBox="0 0 3 3">
    <svg:circle svg:style="fill: yellow;" cx="1.5" cy="1.5" r="0.5"/>
</shape>', true);

print xml_error_string(xml_get_error_code($parser)) . "\n";

Expected result:
Expecting at least one mention of "/NS:...".

Especially one, where parser leaving the enclosed SVG structure.

Actual result:
No error

(No really, there's no error. But... Where's my handlers?)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-16 16:08 UTC]
-Status: Open +Status: Analyzed
 [2016-02-16 16:08 UTC]
Thanks for the reports. How it looks like, the things you've realized do happen most likely not due to a PHP bug, but depend on the libxml2 usage. libxml doesn't support all the available callbacks, and it's documented. From a quick look, have to check deeper, the other tickets you've reported have the same cause. Many Linux distros link with libxml, as well it's used on Windows.

 [2016-02-16 17:59 UTC] anrdaemon at freemail dot ru
Do you think it deserves at least a note in documentation?
You know, it is rather frustrating to write a parser and find out that it just not supposed to work as documented.
 [2016-02-16 20:53 UTC]
-Type: Bug +Type: Documentation Problem
 [2016-02-16 20:53 UTC]
Yeah, clear the documentation could and should be improved. However, with this particular ticket, it's documented , please consider the note on the page:

This event is not supported under LibXML.

Maybe it's not synced with all the available languages, but actually i see that many contain it. What is not documented and I think it's hard to document, is what library is actually used with any particular build in a particular binary distribution. Right now, besides Windows builds at least Debian and Fedora use libxml instead of libxpat, for what i've checked. The main reason I think is that libxml is being supported and updated much more frequently. This info can be however gathered on the corresponding package pages of the respective distributions.

The other three tickets reported by you (just decrementing this ticked number :) need to be checked thoroughly as well, but how it reads from the code snippets and from the code base - the cause seems to be the same. So for now I'm turning this ticket into the documentation issue, lets see with the others.

 [2016-02-16 22:16 UTC] anrdaemon at freemail dot ru
Thanks, I've apparently missed that one note.
Should probably be a warning, and way up on the page, as it would be an impediment on most platforms.
 [2016-07-22 12:45 UTC] rasmus at mindplay dot dk
This should be considered a bug.

The fact that an XML parser API happens to be implemented by library that doesn't work predictably, is an implementation detail - it shouldn't mean that we offer an unpredictable/broken feature in PHP.

I just wasted like half a day before realizing that this function simply doesn't work and just silently fails. (under PHP 7 on Windows)

I then spent several more hours implementing support for xmlns-attributes myself, which was pretty difficult to get right - I suppose everyone who needs xmlns-support has to roll their own, and I'm sure many will get it wrong.

Beyond that, it's hard to imagine how someone managed to even make this feature platform-dependent in the first place?

Either way, having this one feature in an otherwise functional API that just quietly fails, is in my opinion completely unacceptable.
 [2017-01-08 18:41 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #71595: NS end handler is never called
 [2017-01-08 18:50 UTC]
-Type: Documentation Problem +Type: Bug -Assigned To: +Assigned To: cmb
 [2017-01-08 18:50 UTC]
Even though bug #30834 has been closed as "won't fix", IMHO, this
is not just a documentation issue. Either
xml_set_end_namespace_decl_handler() shouldn't be defined, if it
is not supported by the underlying library, or it should at least
trigger a warning when called. For backwards compatibility the
latter appears to be more appropriate.

BTW, can somebody please kill the spam posts above?
 [2017-06-21 08:34 UTC]
-Assigned To: cmb +Assigned To:
 [2020-02-07 06:06 UTC]
Automatic comment on behalf of cmb
Log: Fix #71595: NS end handler is never called
 [2020-02-07 06:06 UTC]
-Status: Analyzed +Status: Closed
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu May 19 22:05:46 2022 UTC