php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73252 DOMXPath: doc passed in constructor not always equals $xpath->document.
Submitted: 2016-10-05 12:41 UTC Modified: -
From: arjen at parse dot nl Assigned:
Status: Open Package: DOM XML related
PHP Version: 7.0.11 OS: Linux
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: arjen at parse dot nl
New email:
PHP Version: OS:

 

 [2016-10-05 12:41 UTC] arjen at parse dot nl
Description:
------------
When passing an object CustomDOMDocument extending DOMDocument as the DOMXPath object, the document property of DOMXpath is of type CustomDOMDocument.

As soon as the original document is destructed (because of scope), a clone of the object is stored internally, but with type DOMDocument and not the CustomDOMDocument class.


See https://3v4l.org/XLInV

Test script:
---------------
<?php


class CustomDOMDocument extends DOMDocument
{
}

function localScope()
{
    $doc = new CustomDOMDocument;
    $doc->loadHtml('<p>Test123</p>');
    $xpath = new DOMXPath($doc);
    
    return $xpath;
}


$doc = new CustomDOMDocument;
$doc->loadHtml('<p>Test123</p>');
$xpath = new DOMXPath($doc);

var_dump(get_class($xpath->document));


$xpath = new DOMXPath(new CustomDOMDocument);
var_dump(get_class($xpath->document));

$xpath = localScope();
var_dump(get_class($xpath->document));

Expected result:
----------------
string(17) "CustomDOMDocument"
string(17) "CustomDOMDocument"
string(17) "CustomDOMDocument"

Actual result:
--------------
string(17) "CustomDOMDocument"
string(11) "DOMDocument"
string(11) "DOMDocument"

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 14:01:25 2019 UTC