Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:8330 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57515 invoked by uid 1010); 3 Mar 2004 01:21:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 57490 invoked from network); 3 Mar 2004 01:21:18 -0000 Received: from unknown (HELO phoebe.host4u.net) (209.150.128.26) by pb1.pair.com with SMTP; 3 Mar 2004 01:21:18 -0000 Received: from ctdprimary (dsta-aa203.pivot.net [66.186.171.203]) by phoebe.host4u.net (8.11.6/8.11.6) with SMTP id i231LH623288 for ; Tue, 2 Mar 2004 19:21:17 -0600 Message-ID: <014501c400be$2190f1f0$f7dea8c0@cyberware.local> To: Date: Tue, 2 Mar 2004 20:23:27 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0142_01C40094.386772C0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Subject: more static method fun From: rrichards@ctindustries.net ("Rob Richards") ------=_NextPart_000_0142_01C40094.386772C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable It is currently impossible to call a true static method from within a = class method. It lets a class method call any object method statically = even when not defined as a static method. The static method being = called inherits the $this from the encapsulating object. This may not be = a big deal with userspace objects, but it is impossible to handle for = internal objects. Within the dom extension there are a few methods which can be called = both statically and off an instantiated object. Calling them statically = works fine until they are called within a class method as the function = either expects this to be defined (meaning an instantiated object) or it = to be null (when it is called statically). Since within the class = method, it magically inherits the this of the object calling it, it = currently crashes. The following is an example using simplexml to illustrate the problem = (simplexml's code base is much smaller so easier to follow). Class AClass { function tester() { print simplexml_element::asXML(); // segfaults as this should not be = allowed to be called statically } } $test =3D new AClass(); $test->tester(); And before someone says that the object type should be tested using = zend_parse_method_parameters as a "workaround", it still wouldnt work = correctly: Class BClass extends simplexml_element { function tester() { print simplexml_element::asXML(); } } $test =3D new BClass(""); $test->tester(); This doesnt crash, but because the static call is being called from = within an object which extends simplexml_element, it would pass and act = as if $this->asXML() was called, which also is incorrect. It should be = issuing the same non-static method cannot be called statically error as = when it is called outside a class. A better example of why it also would = be incorrect would be using a domdocument: Class BClass extends domdocument { var $newdoc =3D NULL; function tester() { $this->newdoc =3D domdocument::loadXML(""); } } $test =3D new BClass(); $test->loadXML("abc"); print $test->saveXML()."\n"; $test->tester(); var_dump($test->newdoc); print $test->saveXML()."\n"; newdoc ends up as a boolean rather than a new document as $test is = actually changed from the static call as it believes it is being called = as $test's method and not as a static method, which should produce a new = document rather than replacing the current document. ------=_NextPart_000_0142_01C40094.386772C0--