Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleXMLElement::asXML differs from Zend for empty elements #2983

Closed
HRMsimon opened this issue Jun 19, 2014 · 14 comments
Closed

SimpleXMLElement::asXML differs from Zend for empty elements #2983

HRMsimon opened this issue Jun 19, 2014 · 14 comments

Comments

@HRMsimon
Copy link

<?php

$a = new SimpleXMLElement("<a/>");
$a->addChild('b');
var_dump($a->asXML());

Expected (Zend) output:

string(34) "<?xml version="1.0"?>
<a><b/></a>
"

Actual output:

string(37) "<?xml version="1.0"?>
<a><b></b></a>
"

The <b> is self-closing under Zend but not HHVM. This only seems to happen with nodes added dynamically. If passed as part of the string used during construction, the outputs both have the self-closing tag.

// @danslo

@danslo
Copy link
Contributor

danslo commented Jun 19, 2014

On it.

@danslo
Copy link
Contributor

danslo commented Jun 24, 2014

$ cat test.php
<?php

$a = new SimpleXMLElement("<a/>");
$a->addChild('b');
var_dump($a->asXML());
$ ./hphp/hhvm/hhvm test.php
string(34) "<?xml version="1.0"?>
<a><b/></a>
"

Try a more recent build? :-)

@HRMsimon
Copy link
Author

It's a LibXML difference. I get the problem with HHVM and libxml2.7.8 though not with PHP and 2.7.8.

@aingram
Copy link
Contributor

aingram commented Oct 12, 2014

On the same topic, empty($a) yields different results in PHP 5.3 and HHVM 3.3 (libxml2.7.8).

@danslo FYI, this affects Magento when configured for separate read-only and read-write databases. In such a configuration, <use/> is often in <connection> in local.xml. Line 1407 in app/code/core/Mage/Core/Model/Config.php (Magento EE 1.12) causes a problem because HHVM thinks $conn->use is not empty.

@danslo
Copy link
Contributor

danslo commented Oct 12, 2014

@aingram Same topic (SimpleXML), but not same issue... So please create a separate issue that has a small reproduction.

@aingram
Copy link
Contributor

aingram commented Oct 13, 2014

Done: #3963

@paulbiss
Copy link
Contributor

paulbiss commented Nov 3, 2014

@danslo can this be closed?

@danslo
Copy link
Contributor

danslo commented Nov 3, 2014

@paulbiss I don't know, I could never reproduce this (seemed to depend on libxml version).

@paulbiss
Copy link
Contributor

paulbiss commented Nov 3, 2014

Thanks!

@HRMsimon
Copy link
Author

HRMsimon commented Nov 3, 2014

@paulbiss this is still an problem (at least with 3.3.1):

root@release-app:~# cat test.php 
<?php

$a = new SimpleXMLElement("<a/>");
$a->addChild('b');
var_dump($a->asXML());
root@release-app:~# hhvm test.php 
string(37) "<?xml version="1.0"?>
<a><b></b></a>
"
root@release-app:~# hhvm --version
HipHop VM 3.3.1 (rel)
Compiler: tags/HHVM-3.3.1-0-ge0c98e21167b425dddf1fc9efe78c9f7a36db268
Repo schema: f53e1743f31a2dee70c46aa66fb1b321c3e97c10
Extension API: 20140829
root@release-app:~# php test.php 
string(34) "<?xml version="1.0"?>
<a><b/></a>
"
root@release-app:~# php --version
PHP 5.5.12-2+deb.sury.org~precise+1 (cli) (built: May 12 2014 13:46:35) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
root@release-app:~# dpkg -l | grep libxml2
ii  libxml2                              2.7.8.dfsg-5.1ubuntu4.11             GNOME XML library
ii  libxml2-dev                          2.7.8.dfsg-5.1ubuntu4.11             Development files for the GNOME XML library

HHVM matches PHP with a later libxml version (whatever Ubuntu 14.04 has), but is different with this one (Ubuntu 12.04)

@paulbiss
Copy link
Contributor

paulbiss commented Nov 3, 2014

I can re-open this as a "build" issue but if the issue is with an external library it's unlikely there will be a fix on our end.

@HRMsimon
Copy link
Author

HRMsimon commented Nov 3, 2014

From what I can tell, it's more an interface issue. PHP and HHVM are using the exact same libxml version, but HHVM has different behaviour

@paulbiss paulbiss added the build label Nov 3, 2014
@paulbiss paulbiss reopened this Nov 3, 2014
@simonwelsh
Copy link
Contributor

Did a bit of digging and it appears that it's down to xmlIsXhtml (part of libxml), which checks for a XHTML DTD and then outputs self closing tags. Don't know why PHP has it return 1 when HHVM doesn't though.

@Orvid
Copy link
Contributor

Orvid commented Apr 29, 2016

This works on the current version of HHVM. https://3v4l.org/BAnGT

@Orvid Orvid closed this as completed Apr 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants