|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45879 Cannot clone objects due to 'zend.ze1_compatibility_mode' on NodeList::item
Submitted: 2008-08-21 09:44 UTC Modified: 2008-08-21 10:59 UTC
From: olivier dot berger at it-sudparis dot eu Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.6 OS: Debian lenny
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: olivier dot berger at it-sudparis dot eu
New email:
PHP Version: OS:


 [2008-08-21 09:44 UTC] olivier dot berger at it-sudparis dot eu
When zend.ze1_compatibility_mode is on, there are clone problems when iterating over the DOMNodelist items

With the following code, I get :
Fatal error: Cannot clone object of class DOMText due to 'zend.ze1_compatibility_mode' for instance

Reproduce code:
ini_set('zend.ze1_compatibility_mode', true);
$doc =& new DOMDocument();
$success = $doc->load('/tmp/test.xml');
$root =& $doc->documentElement;
$nodeList = &$doc->documentElement->childNodes;
for ($i = 0; $i < $nodeList->length; ++$i) {
    $node = &$nodeList->item($i);
    echo "$i - ";
    $nodeName = $node->nodeName;
    echo "$nodeName :";
    $nodeValue = $node->nodeValue;
    echo "$nodeValue <br/>";

Expected result:
I would expect it to display the XML file's contents as without zend.ze1_compatibility_mode (in which case it works)

Actual result:
I get "Cannot clone object of class DOMText" wether with :
$node = &$nodeList->item($i);
or :
$node = $nodeList->item($i);

a :
foreach ($nodeList as $node) {
    echo $node->nodeName;
    echo $node->nodeValue;
won't work either.

I guess that the internals of DOMNodelist::item tries to clone them instead of returning them by address, then.

Note that :
for ($i = 0; $i < $nodeList->length; ++$i) {
    echo "$i - ";
    $nodeName = $nodeList->item($i)->nodeName;
    echo "$nodeName :";
    $nodeValue = $nodeList->item($i)->nodeValue;
    echo "$nodeValue <br/>";
seems to work, though.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-21 10:59 UTC]
Using ze1 compatibility you tell the "=" oeprator (and fucntion calls and ...) you want a copy of the object, some classes can't be copied (cloned) you'D have to use explecit references ($a =&$b) but at first you don't want to mix PHP 4 code relying on that setting with PHP 5 code.

btw. that problem is one of the reasons why ze1 compatibility mode is being dropped with 5.3. 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 02:01:23 2020 UTC