Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20065 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31382 invoked by uid 1010); 16 Nov 2005 15:55:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 31367 invoked from network); 16 Nov 2005 15:55:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2005 15:55:50 -0000 X-Host-Fingerprint: 195.227.108.51 wfserver02.wf-ppr.de Windows 2000 SP2+, XP SP1 (seldom 98 4.10.2222) Received: from ([195.227.108.51:22443] helo=wfserver02.wf-ppr.de) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 0D/CD-07637-5865B734 for ; Wed, 16 Nov 2005 10:55:50 -0500 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.5.6944.0 Date: Wed, 16 Nov 2005 16:55:45 +0100 Message-ID: <00A2E2156BEE8446A81C8881AE117F192C1B31@companyweb> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] interface method visibility. Thread-Index: AcXqwepOQM5TE2njRGKDYz59vIfhkQAAKYoA To: Subject: AW: [PHP-DEV] interface method visibility. From: mp@webfactory.de ("Matthias Pigulla") > why does the engine care about the visibility of interface=20 > methods I declare? > I understand the argument that interface methods only have=20 > 'meaning' when applied as public methods of objects - but=20 > thats rather academic and personally I can think of useful=20 > ways to abuse interfaces using protected methods at the very=20 > least why am I not allowed to do this just because someone=20 > decided that its not correct? Having anything else than "public" in an interface simply does not make any sense - an interface serves as a contract to external clients. It guarantees them that there will be a set of methods they can call on an object instance. What should be the semantic meaning of non-public elements in interfaces? > and given that I can implement a non-static method without=20 > using $this or any other symbol/code related to the=20 > instantiated object (effectively creating a static method)=20 > which I can call using static notation why not allow static=20 > interface methods? As to static interface methods - same as above. An interface is an interface :), not an implementation. So you will never have methods implemented in an interface. The interface just says "the class implementing the interface has a method named xy() that you can call". So how would you make the static call on the interface? ISomewhat::someMethod()? Where should that be implemented? This is why you always need an instance that implements the interface and you make a "normal" call on this instance. PHP allows - as opposed to C# or Java (IIRC) - to call static methods on instances. I think the fact that you can call nonstatic methods statically is BC with "early days"; you don't want to do that in your code because it will get you problems sooner or later. In "older" code you could not mark methods as static, so the language could not check if a static call is allowed. It simply permitted the call, not setting $this. > also I noticed that using the keyword 'abstract' with a=20 > interface method declaration is all of a sudden (5.1RC5dev)=20 > causing a fatal error where before (5.0.2 - 5.0.4) no error=20 > what so ever. I thought I would never write anything like that - but: What sense does "abstract" make in an interface at all? You shouldn't have been writing "abstract" in an interface in the first place. >:) > If 'static', 'protected', 'private' are not allowed with=20 > interfaces (very unpragmatic imho) then why the fatal errors?=20 > why not an E_STRICT and just ignore those declaration...=20 As I understand it, E_STRICT is for complaining about stuff like "var" that was ok with PHP4 but is discouraged in PHP5. But you are using PHP5 elements in a way that make no sense to the language, so it's simply an error. > especially because not declaring a method static and leaving=20 > off the visibility leaves you with a method that is=20 > non-static and public - exactly what an interface 'requires'. You're explicitly requesting something that is not possible - an fatal error is the only thing that can be the result. Matthias