Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-8427

elementByAttributeValue destroys Children array, in eZDOMNode - patch included

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • 3.10.0beta1, 3.8.9, 3.9.3, 4.0.0alpha1
    • 3.7.5
    • Misc
    • None
    • Version: 3.7.5
      PHP Version: 4.4.2
      Webserver: Apache 1.3
      Database: MySQL

    Description

      There is a bug in eZDOMNode::elementByAttributeValue that makes it destroy the last element in the Children array when there are no matches.

      I was trying to build an XML document without duplicate elements, but ended up with an error message:

      Fatal error: Call to a member function on a non-object in /var/www/vhosts/arkivplan/html/lib/ezxml/classes/ezdomnode.php on line 429

      Code to reproduce:

      require_once('lib/ezxml/classes/ezxml.php');
      $doc=&new eZDOMDocument('Document');
      $node=&$doc->createElementNode('RootNode');
      $doc->setRoot($node);
      foreach(array('A','B','C') as $attrib) {
      if ($node->elementByAttributeValue('attr',$attrib)===false)

      { $node->appendChild($doc->createElementNode('SubNode',array('attr'=>$attrib))); }

      }

      This will cause the abovementioned error on the third iteration.

      The problem is that the function loops through the children by reference, then when no element is found, the same variable is set to false(not by reference), thus overwriting the value in the array. My simplest solution is to use a different variable name, see attached patch.

      Attachments

        Activity

          People

            dl dl
            edorfaus edorfaus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: