php.net |  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
Votes:1
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
 [2016-02-15 02:38 UTC] anrdaemon at freemail dot ru
Description:
------------
When NS-aware parser is created, the handler set by xml_set_end_namespace_decl_handler() is never called.

Test script:
---------------
<?php
$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" "http://www.daa.com.au/~james/dia-shape-ns">
<shape>
  <svg xmlns:svg="http://www.w3.org/2000/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"/>
  </svg>
</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?)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-16 16:08 UTC] ab@php.net
-Status: Open +Status: Analyzed
 [2016-02-16 16:08 UTC] ab@php.net
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.

Thanks.
 [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] ab@php.net
-Type: Bug +Type: Documentation Problem
 [2016-02-16 20:53 UTC] ab@php.net
Yeah, clear the documentation could and should be improved. However, with this particular ticket, it's documented http://php.net/xml_set_end_namespace_decl_handler , 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.

Thanks.
 [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] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=341634
Log: Fix #71595: NS end handler is never called
 [2017-01-08 18:50 UTC] cmb@php.net
-Type: Documentation Problem +Type: Bug -Assigned To: +Assigned To: cmb
 [2017-01-08 18:50 UTC] cmb@php.net
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] cmb@php.net
-Assigned To: cmb +Assigned To:
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=47065812c2450dce5dcc8d62e80f1e75698c6163
Log: Fix #71595: NS end handler is never called
 [2020-02-07 06:06 UTC] phpdocbot@php.net
-Status: Analyzed +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC