php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53693 ::transformToDoc() $returnClass param docs insufficient
Submitted: 2011-01-08 05:31 UTC Modified: 2023-09-30 11:43 UTC
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: mat at homedvd dot ca Assigned: nielsdos (profile)
Status: Closed Package: XSLT related
PHP Version: Irrelevant OS: Any
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: mat at homedvd dot ca
New email:
PHP Version: OS:

 

 [2011-01-08 05:31 UTC] mat at homedvd dot ca
Description:
------------
It would be very helpful to allow transformToDoc to return a custom class instance, which would have to extend DOMDocument of course.

The example code provided is simplified.  Far better usage could be made from the child DOMDocument class -- this is only an example to illustrate the potential.

Test script:
---------------
class DOMDocumentYouCanFancyPrint extends DOMDocument {
    public function __toString() {
        return "<pre>" . htmlentities( $this->saveXML() ) . "</pre>";
    }
}

...

$processor->registerDocumentClass( "DOMDocumentYouCanFancyPrint" );
echo $processor->transformToDoc( $sourceDOM );

Expected result:
----------------
The expected result would be that the transformToDoc method call returns an instance of DOMDocumentYouCanFancyPrint.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-15 16:38 UTC] cmb@php.net
-Summary: transformToDoc, different class +Summary: ::transformToDoc() $returnClass param docs insufficient -Status: Open +Status: Verified -Type: Feature/Change Request +Type: Documentation Problem
 [2021-09-15 16:38 UTC] cmb@php.net
This is possible for a long time (at least as of PHP 5.3) by using
the almost undocumented 2nd parameter of ::transformToDoc() which
expects the name of the class to return.  In your case:

echo $processor->transformToDoc( $sourceDOM, DOMDocumentYouCanFancyPrint::class );
 [2023-09-30 11:43 UTC] nielsdos@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: nielsdos
 [2023-09-30 11:43 UTC] nielsdos@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

I added documentation for this parameter.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC