php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48352 Method registerNodeClass does not work with DOMNodeList
Submitted: 2009-05-21 09:38 UTC Modified: 2017-10-24 06:15 UTC
Votes:10
Avg. Score:4.6 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:1 (12.5%)
Same OS:0 (0.0%)
From: php at xxlwebdesign dot de Assigned:
Status: Open Package: DOM XML related
PHP Version: 5.3CVS-2009-05-21 (snap) OS: Gentoo
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at xxlwebdesign dot de
New email:
PHP Version: OS:

 

 [2009-05-21 09:38 UTC] php at xxlwebdesign dot de
Description:
------------
The method DOMDocument->registerNodeClass does not work with DOMNodeList

Reproduce code:
---------------
<?php

class MyNodeList extends DOMNodeList
{
	
}

$dom = new DOMDocument();
$dom->registerNodeClass('DOMNodeList', 'MyNodeList');

?>

Actual result:
--------------
Fatal error: DOMDocument::registerNodeClass() [<a href='domdocument.registernodeclass'>domdocument.registernodeclass</a>]: Class DOMNodeList is not derived from DOMNode. in ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-22 10:49 UTC] rrichards@php.net
This method was designed specifically for DOMNode based classes only. 
changing to feature request and I will consider and evaluate expanding 
its functionality.
 [2009-05-22 12:53 UTC] php at xxlwebdesign dot de
This would be very nice!
 [2009-09-20 21:17 UTC] goetas at lignano dot it
this would be really helpful!
 [2010-02-15 02:45 UTC] mail at r-site dot net
very helpfull, extending DOMNode's almost implies it, pls hurry, ty
 [2011-01-08 05:17 UTC] mat at homedvd dot ca
Any movement on this? The method should probably be called registerNodeListClass
 [2011-02-21 20:41 UTC] jani@php.net
-Package: Feature/Change Request +Package: DOM XML related
 [2012-01-03 13:40 UTC] kroccamen at gmail dot com
I’d like to provide a valid use-case for this bug.

I have created an extended DOMDocument that upon __construct also creates an  XPath object, that way I can add methods to DOMElement to allow for DOMElement->xpath ('...') instead of using DOMXPath->query ('...', DOMNode). This makes the DOM more chainable and simpler to use without so many temporary variables.

What I want to do is extend DOMNodeList so that one function call can apply to all nodes returned from an XPath query, e.g.

DOMNode->xpath ('a')->addClass ('link');

Is anybody aware of any other work around that can be used to achieve this same effect?
 [2013-05-01 14:02 UTC] troelskn at gmail dot com
@kroccamen While not that elegant, you can create a decorator to solve this issue. Here's a template to use:

    class MyDomElement extends DOMElement {
      function xpath($query) {
        return new DomNodeListDecorator($this->ownerDocument->getXpathSelector()-
>query($query, $this));
      }
    }

    class DomNodeListDecorator implements IteratorAggregate {
      protected $nodeList;

      function __construct($nodeList) {
        $this->nodeList = $nodeList;
      }

      function getIterator() {
        return $this->nodeList;
      }

      function __get($name) {
        if ($name == 'length') {
          return $this->nodeList->length;
        }
        throw new Exception("Undefined attribute {$name}");
      }

      function item($index) {
        return $this->nodeList->item($index);
      }
    }
 [2017-10-24 06:15 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: rrichards +Assigned To:
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC