# DOMDocument->saveXML with node parameter

- Thread: https://externals.io/message/59099
- Original archive: https://news-web.php.net/php.internals/59099
- Started by Nicolai Scheer on 2012-03-20T22:27:50+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #59099 — Nicolai Scheer — 2012-03-20T22:27:50+00:00

URL: https://externals.io/message/59099#59099

Hi!

Just stumbled upon the issue described in

https://bugs.php.net/bug.php?id=39771

during a Windows -> Linux migration.

The windows binaries for php 5.3.10 and 5.4 got no problems executing
the following:

<?php
$doc = new DOMDocument();
$doc->loadHTML( '<html><body>Test</body></html>' );
$body = $doc->getElementsByTagName( 'body' )->item( 0 );
echo $doc->saveHTML( $body );

If I compile 5.3.10 myself (RHEL 5.7), I get the very same behaviour as
described in the last comment of bug 39771:

"PHP Warning:  DOMDocument::saveHTML() expects exactly 0 parameters, 1
given"

A quick look at the sources of 5.3.10 show, that there is indeed a
optional node parameter:

ext/dom/document.c:2296:

if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
"O|O!", &id, dom_document_class_entry, &nodep, dom_node_class_entry) ==
FAILURE) {
  return;
}

Yet, the arginfo does not reflect this, e.g.

ext/dom/document.c:158:

ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
ZEND_END_ARG_INFO();

should read

ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
  ZEND_ARG_OBJ_INFO(0, node, DOMNode, 1)
ZEND_END_ARG_INFO();

If I allow for passing that optional parameter by adjusting the arginfo,
the php snippet posted above works just fine.

The documentation of DOMDocument::saveHTML is in sync with the
implementation of dom_document_save_html, it seems that just the
parameter checking is wrong.

It is very confusing, that the provided windows binaries work, but the
compiled-it-myself php on linux does not.

Any insight on the correctness of this (documented) feature as well as
the windows / linux discrepancy is very appreciated.

Sincerely,

Nico

---

## #59100 — Gustavo Lopes — 2012-03-20T22:33:10+00:00

URL: https://externals.io/message/59099#59100 · In reply to: #59099

On Tue, 20 Mar 2012 23:27:50 +0100, Nicolai Scheer <scope@planetavent.de>  
wrote:

>
> <?php
> $doc = new DOMDocument();
> $doc->loadHTML( '<html><body>Test</body></html>' );
> $body = $doc->getElementsByTagName( 'body' )->item( 0 );
> echo $doc->saveHTML( $body );
>
> If I compile 5.3.10 myself (RHEL 5.7), I get the very same behaviour as
> described in the last comment of bug 39771:
>
> "PHP Warning:  DOMDocument::saveHTML() expects exactly 0 parameters, 1
> given"
>
> A quick look at the sources of 5.3.10 show, that there is indeed a
> optional node parameter:
>
> ext/dom/document.c:2296:
>
> if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
> "O|O!", &id, dom_document_class_entry, &nodep, dom_node_class_entry) ==
> FAILURE) {
>   return;
> }
>
> Yet, the arginfo does not reflect this, e.g.
>
> ext/dom/document.c:158:
>
> ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
> ZEND_END_ARG_INFO();
>
> should read
>
> ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
>   ZEND_ARG_OBJ_INFO(0, node, DOMNode, 1)
> ZEND_END_ARG_INFO();
>
> If I allow for passing that optional parameter by adjusting the arginfo,
> the php snippet posted above works just fine.
>
> The documentation of DOMDocument::saveHTML is in sync with the
> implementation of dom_document_save_html, it seems that just the
> parameter checking is wrong.
>

While the arginfo is in fact wrong and should be fixed, it cannot have the  
impact you're describing. The wrong arginfo for internal functions only  
affects reflection (except if it has typehints for classes).

Most likely, you're loading an old version of the DOM extension (compiled  
with an earlier version of PHP 5.3).

-- 
Gustavo Lopes

---

## #59102 — Nicolai Scheer — 2012-03-20T23:05:53+00:00

URL: https://externals.io/message/59099#59102 · In reply to: #59100

Hi!


> On Tue, 20 Mar 2012 23:27:50 +0100, Nicolai Scheer
> <scope@planetavent.de> wrote:
> 
> > […]
> 
> While the arginfo is in fact wrong and should be fixed, it cannot have
> the impact you're describing. The wrong arginfo for internal functions
> only affects reflection (except if it has typehints for classes).
> 
> Most likely, you're loading an old version of the DOM extension
> (compiled with an earlier version of PHP 5.3).

I see. I indeed did use the dom.so shipped with RHEL 5.7 (which delivers
php 5.3.3 if I remember correctly), but compiled php 5.3.10 on top of
it, still using the old packetized dom extension.

So I didn't fix it by adding the arginfo, but by using the self-compiled
dom extension from 5.3.10...

Thanks for pointing that out!

Greetings,

Nico
