Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79234 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15816 invoked from network); 27 Nov 2014 15:35:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Nov 2014 15:35:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=guilhermeblanco@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.175 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@gmail.com X-Host-Fingerprint: 209.85.223.175 mail-ie0-f175.google.com Received: from [209.85.223.175] ([209.85.223.175:63457] helo=mail-ie0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/F3-27910-9A447745 for ; Thu, 27 Nov 2014 10:35:06 -0500 Received: by mail-ie0-f175.google.com with SMTP id at20so4708512iec.34 for ; Thu, 27 Nov 2014 07:35:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=sCITAnq2SthYD/rwjQ1hZr2SO84k48xlRc2FFy56GaM=; b=cFha2Kb/1oGHWpC3ZVbLf0QrueeYZYNI2yOmU5mnrPlj6Pyj6T9pieIKbYgjH8ajFW L4O6lN40XUkfLgIIgp+azEytcxukoEN/3cyQWo15c1n9Y8Uv1zOP0TZJlsjc9o21fy56 Mjkd2FYmG233tunjx7n2UY0C0B8XMyd7vP1pzWmqWFOFrBlqTOY35nzPIsVWccAkrvps r6VcrXXweK7u3eynULNrRoxpqhiUsfm1dd2AB7CePzWHt32Z0UumzQyZXZDuvz+xZlL2 oqI4b6gk4uv0juJg7MeCitu0zAINjJvnY/HpVauRjqlV3foHiwme9yunW7DHRiBcRnAx CJqQ== X-Received: by 10.107.38.202 with SMTP id m193mr11614617iom.19.1417102502701; Thu, 27 Nov 2014 07:35:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.238.75 with HTTP; Thu, 27 Nov 2014 07:34:42 -0800 (PST) In-Reply-To: <54773DD8.7030907@gmail.com> References: <547723A8.8090008@gmail.com> <54773DD8.7030907@gmail.com> Date: Thu, 27 Nov 2014 10:34:42 -0500 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1140751048b2c80508d8e30d Subject: Re: [PHP-DEV] [RFC] Abstract final classes From: guilhermeblanco@gmail.com ("guilhermeblanco@gmail.com") --001a1140751048b2c80508d8e30d Content-Type: text/plain; charset=UTF-8 > This is true of classes intended to be static whether or not they are final. Allowing a "static class" would allow you to > enforce that all methods (and properties) must be static without banning users from extending it (which is a completely > orthogonal decision). So if I still want to not allow anyone to extend it, I would then have a final static class. Remember, I don't want people to change methods' visibility. How does that become different from final abstract? I know you answered below... =) > That's not how they're interpreted with regard to methods, unless I'm missing something: > > - "abstract function" means a method which must be implemented by a sub-class > - "static function" means a method with no access to $this, operating outside of any instance > > Taking those behaviours for class definitions leads to the interpretation that seems natural to me: > > - "abstract class" means a class which must be extended before use, and may contain abstract methods > - "static class" would mean a class which can never be used to create an instance, and can contain only static methods > > "final" is orthogonal to these, and means that a class cannot be extended; under this interpretation, "abstract final" is a > contradiction, but "static final" makes perfect sense. The piece it's missing in "static" definition: there can only be one instance of something. I'd argue that declaring a class static is the same as declaring a singleton. Multiple object instantiations over a static class would return always same instance. Now taking this into consideration, I'd modify your concepts to the following: - "abstract function" means a method which must be implemented by a sub-class - "static function" means a method with no access to $this, operating outside of any instance. This means it's bound to class entry, which can only have one possibility to be called: statically and given same parameters it should return same output, unless normal flow controlled by a static variable. I'm more than happy to change "abstract" to "static" if it's the desire of everybody. That would match C# implementation as defined here: http://msdn.microsoft.com/en-us/library/79b3xss3.aspx Now it's funny that C# also accepts "abstract final" with the same idea/concept of their documentation of static classes. #weird []s, On Thu, Nov 27, 2014 at 10:06 AM, Rowan Collins wrote: > guilhermeblanco@gmail.com wrote on 27/11/2014 14:08: > >> > In the RFC, I think one phrase needs clarification: >> > >> > Currently, PHP developers' only resource is to create a final class with >> > a private constructor, leading to untestable and error prone code. >> > >> > What is "error prone" in private __construct(); and how the RFC improves >> > the testability of such class? >> >> The reason comes not to the construct method itself, but to other >> implemented methods. >> By forgetting "static" in any of your declared methods, you get no parse >> error and gives you 2 possibilities: >> - With E_STRICT enabled: Fatal error when non-static method is being >> statically called. You'll only get this at runtime, leading to potentially >> error prone. Now the testability come that with this addiction, you get a >> fatal error, which is easily fixable at compile time, not runtime. >> - With E_STRICT disabled: You get a warning on php log and everything >> works (which is a huge wtf mode). >> > > This is true of classes intended to be static whether or not they are > final. Allowing a "static class" would allow you to enforce that all > methods (and properties) must be static without banning users from > extending it (which is a completely orthogonal decision). > > > > "Abstract final" is a strange way to name it. What you want is a >> "static" class: >> >> > This has always been my feeling. To me, "abstract" means "must be >> extended", and "final" means "can't be extended", so > combining the two >> seems like a self-contradiction. >> > >> > The fact that abstract classes allow static methods to be called >> without sub-classing always seems a bit odd to me - it's as > though only >> the constructor is really abstract, not the whole class. >> > >> > A "static" class, however, whether "final" or not, is definitely >> something I've wanted. >> >> > for the record I also brought up this argument (abstract and final being >> > contradicting ideas) in the pull request comments(before this thread was >> > created). >> >> No, because conceptually, a static something means that subsequent calls >> always return same value. A static class means a singleton, not what this >> patch proposal. >> You have to remember: >> - "abstract" means it cannot be instantiated directly >> - "final" means it cannot be extended >> > > That's not how they're interpreted with regard to methods, unless I'm > missing something: > > - "abstract function" means a method which must be implemented by a > sub-class > - "static function" means a method with no access to $this, operating > outside of any instance > > Taking those behaviours for class definitions leads to the interpretation > that seems natural to me: > > - "abstract class" means a class which must be extended before use, and > may contain abstract methods > - "static class" would mean a class which can never be used to create an > instance, and can contain only static methods > > "final" is orthogonal to these, and means that a class cannot be extended; > under this interpretation, "abstract final" is a contradiction, but "static > final" makes perfect sense. > > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Guilherme Blanco MSN: guilhermeblanco@hotmail.com GTalk: guilhermeblanco Toronto - ON/Canada --001a1140751048b2c80508d8e30d--