php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41398 DOMDocument->loadXML() documents static is okay, but gives E_STRICT
Submitted: 2007-05-15 12:48 UTC Modified: 2010-11-10 23:01 UTC
Votes:7
Avg. Score:3.4 ± 1.5
Reproduced:5 of 6 (83.3%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: RQuadling at GMail dot com Assigned: salathe (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.4-dev OS: Windows XP SP2
Private report: No CVE-ID: None
 [2007-05-15 12:48 UTC] RQuadling at GMail dot com
Description:
------------
DOMDocument->loadXML() is documented as being able to be called statically - DOMDocument::loadXML()

But this generates a strict error.

I don't know if this is doc bug or a libxml/DOM bug.

$doc will be correctly populated and workable.

I know that "loadXML() is not a true static function. It is just allowed to be called statically. When called statically within a method of an instantiated DOMDocument object it acts as if the method had been called directly from the object itself rather than statically." (I've read the bugs), but what does this mean for the user where the documentation says it a static call IS allowed and the that the static call actually works (but gives the Strict warning).

The error says "should not", not "cannot". 

In looking at all the methods in all the extensions in php-src, all those with ZEND_ACC_ALLOW_STATIC, when called statically, result in the warning shown.

Either it shouldn't be allowed to be called Statically (and the documentation amended to remove this option) or it should be allowed to be called statically (and the strict message is removed).

Either way something isn't right.

There are only 4 files in the whole of the php-src/ext folder with ZEND_ACC_ALLOW_STATIC

com_persist.c, document.c, domimplementation.c and php_xmlreader.c

The example in the dox for DOMImplementation->hasFeature() uses a static call ...

...
 if (DOMImplementation::hasFeature($key, '2.0')) {
...

And this results in a lot of Strict errors.

Clearly, not what you would be expecting.

Without the ZEND_ACC_ALLOW_STRICT, I assume you wouldn't be able to call them statically (it seems that way in zend_vm_execute.h, so should this be removed from these extensions?

Reproduce code:
---------------
<?php
$domxml = DOMDocument::loadXML('<root><node /></root>');
$domhtml = DOMDocument::loadHTML('<html><head><title>Title</title></head><body>Stuff</body></html>');
$xmlxml = XMLReader::XML('<html><head><title>Title</title></head><body>Stuff</body></html>');

$features = array(
 'Core'           => 'Core module',
 'XML'            => 'XML module',
 'HTML'           => 'HTML module',
 'Views'          => 'Views module',
 'Stylesheets'    => 'Style Sheets module',
 'CSS'            => 'CSS module',
 'CSS2'           => 'CSS2 module',
 'Events'         => 'Events module',
 'UIEvents'       => 'User interface Events module',
 'MouseEvents'    => 'Mouse Events module',
 'MutationEvents' => 'Mutation Events module',
 'HTMLEvents'     => 'HTML Events module',
 'Range'          => 'Range module',
 'Traversal'      => 'Traversal module'
);
              
foreach ($features as $key => $name) {
 if (!DOMImplementation::hasFeature($key, '2.0')) {
   echo "Has feature $name\n";
 } else {
   echo "Missing feature $name\n";
 }
}

?>

Expected result:
----------------
Has feature Core module
Missing feature XML module
Has feature HTML module
Has feature Views module
Has feature Style Sheets module
Has feature CSS module
Has feature CSS2 module
Has feature Events module
Has feature User interface Events module
Has feature Mouse Events module
Has feature Mutation Events module
Has feature HTML Events module
Has feature Range module
Has feature Traversal module

Actual result:
--------------
Strict Standards: Non-static method DOMDocument::loadXML() should not be called statically in C:\static_calls.php on line 2

Strict Standards: Non-static method DOMDocument::loadHTML() should not be called statically in C:\static_calls.php on line 3

Strict Standards: Non-static method XMLReader::XML() should not be called statically in C:\static_calls.php on line 4

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Core module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Missing feature XML module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature HTML module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Views module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Style Sheets module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature CSS module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature CSS2 module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Events module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature User interface Events module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Mouse Events module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Mutation Events module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature HTML Events module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Range module

Strict Standards: Non-static method DOMImplementation::hasFeature() should not be called statically in C:\static_calls.php on line 24
Has feature Traversal module

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-16 11:56 UTC] rrichards@php.net
It is there for convenience (even though there are some that do not agree with it) - and its not going to be changed in any event for BC reasons.

When E_STRICT is enabled the user is told that Strict standards are enabled and that they should not call the method statically (it says should not because the call still works).

When E_STRICT is not enabled then no messages and no problems (and again is still works).
 [2007-05-16 12:02 UTC] RQuadling at GMail dot com
So, should the documentation by amended to say that whilst they CAN be called statically, they shouldn't.

It is trying to define the reason why they shouldn't be called that is the problem.

I'm not an internals guy, but it if DOES work, even with E_STRICT, why does it report it as a problem at all.

I can appreciate a WFx on this - if it works why break it.

I suppose what I'm trying to work out is why is it NOT strict OOP? Calling a static method is just what is being done and it IS working and no-one can tell why it is a problem to do so.
 [2007-05-16 12:08 UTC] RQuadling at GMail dot com
I would propose that this E_STRICT warning is removed, allowing the methods to be called statically and NOT generate a warning.

I understand that in userland classes, calling a non static method statically is wrong (because the original developer didn't say the method could be called statically), but in the case of the few methods in DOM/XMLReader (and untested the one in persistent COM), they HAVE been declared static, so they CAN be called statically and therefore they ARE following strict rules.

It seems to me anyway.

I know I've missed something here. Is it that internal classes and userland classes are treated differently internally? (I can't see that being the case as you'd have to maintain 2 different models of operation for the same thing).
 [2007-05-16 13:13 UTC] rrichards@php.net
This is specific to internal classes using the ZEND_ACC_ALLOW_STRICT flag (not a true static method). Technically there should be methods with different names (one static and one non-static) - hence the E_STRICT message so the user can then decide whether to break strict standards or not.

This is something that most likely needs to be clarified in the docs (you can but in most cases shouldn't)
 [2010-09-05 05:22 UTC] philip@php.net
-Summary: [chm] bug on function.dom-domdocument-loadxml.html +Summary: DOMDocument->loadXML() documents static is okay, but gives E_STRICT -Status: Wont fix +Status: Verified -Type: Bug +Type: Documentation Problem -PHP Version: 5CVS-2007-05-15 (snap) +PHP Version: 5.3.4-dev
 [2010-09-05 05:22 UTC] philip@php.net
Type->Doc_Problem (I was just bitten by this)
 [2010-10-22 15:50 UTC] kalle@php.net
-Package: DOM XML related +Package: Documentation problem
 [2010-11-10 22:34 UTC] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=305261
Log: Added common E_STRICT error paragraph for ZEND_ACC_ALLOW_STRICT methods called statically. See #41398
 [2010-11-10 23:01 UTC] salathe@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: salathe
 [2010-11-10 23:01 UTC] salathe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:22 2019 UTC