php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43107 access level of DOM* properties are not applied
Submitted: 2007-10-26 07:02 UTC Modified: 2007-11-14 16:56 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: php at benjaminschulz dot com Assigned: rrichards (profile)
Status: Wont fix Package: DOM XML related
PHP Version: 5.3CVS-2007-10-26 (CVS) OS:
Private report: No CVE-ID: None
 [2007-10-26 07:02 UTC] php at benjaminschulz dot com
Description:
------------
I need to restrict the direct setting of DOM* properties to ensure that no non-utf8 encoding is getting into the Document because libxml2 (ext/dom?) still can't handle that. Implementing this i discovered that classes derived from DOM* cannot restrict the access level of properties.
I think there should at least be an error raised telling that it is not allowed to change the access level of properties, but because of libxml's great  segfaulting abilities i would prefer to able to restrict the access (without a magic setter). Another solution for the encoding problem might be to just check _all_ incoming strings into the DomDocument for unicode if the documents encoding is UTF-8.

Reproduce code:
---------------
<?php
class Test extends DomDocument {
    protected $textContent;   
}

$test = new Test;
$test->loadXml('<foo>bar</foo>');
var_dump($test->textContent);

Expected result:
----------------
Fatal Error: Cannot access protected property Text::$textContent

Actual result:
--------------
string(3) "bar" 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-12 10:12 UTC] tony2001@php.net
Assigned to the maintainer.
 [2007-11-13 06:42 UTC] chregu@php.net
Rob, can you look into that? I have no idea about that part of code, not 
even if it's possible :)
 [2007-11-14 16:00 UTC] rrichards@php.net
First off you can't make the visibility of properties stricter.
DOM properties can't be overridden because there would then be no way to access the underlying functionality. I don't see a way to provide any warnings for this, due to how the way properties are implemented in DOM, so just comes down to the fact that you cant override DOM properties and to validate your input.
 [2007-11-14 16:18 UTC] php at benjaminschulz dot com
"DOM properties can't be overridden because there would then be no way 
to
access the underlying functionality."

That's exactly the point - i don't want some functionality to be 
accessed. If i would want to use the DomDocument as it is i won't need 
to extend it, right?
 [2007-11-14 16:56 UTC] rrichards@php.net
What I'm saying is that the properties being final is the limiting factor when extending the DOM classes and was done purposely.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 01:01:28 2024 UTC