php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
Description:
------------
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:
---------------
<?php
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-21 10:59 UTC] johannes@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 21:01:27 2025 UTC