Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79349 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40211 invoked from network); 1 Dec 2014 18:54:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2014 18:54:28 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wg0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:61039] helo=mail-wg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1B/31-32869-369BC745 for ; Mon, 01 Dec 2014 13:54:28 -0500 Received: by mail-wg0-f48.google.com with SMTP id y19so14879892wgg.21 for ; Mon, 01 Dec 2014 10:54:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=WmcxQvcJ0ea4vofxksZJI1oHQarZoP/GtEs2yAUln2c=; b=DqPOn0GVyvPVTsp3WfB+dDOG/DSIuxbvSEKsMSbSH2FyeCvMUtuwdHUQHHBh8hhIjd txEHsr0XN4SRqCFcRPCp9YY7PyxzqtLqQp/FOYXKE+txUl/ut4isV/BCTLY4khZP6Fs8 f7/QX0CEVYadVtNNpyhZFY/Q+axQkN/XZT5RNiJ2eBgitcgZd4u4yPz3RqH7IFBGLH1N 1CmE3y3UT/QS28nbczUce6qR2m9nuvPmBWxxA6oCoEG5NsMD+cTIhMAuEr4YXmA6O2jS YvOzP2fQG7MHIAqQwkrN5zEQ5cAOK+Ay6yxIrLi4QhS7J4HpFS3fYJqtknytRYD3x9AS AAeg== X-Received: by 10.194.48.109 with SMTP id k13mr39744302wjn.7.1417460064821; Mon, 01 Dec 2014 10:54:24 -0800 (PST) Received: from [192.168.0.148] ([62.189.198.114]) by mx.google.com with ESMTPSA id bj3sm6446974wib.3.2014.12.01.10.54.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Dec 2014 10:54:24 -0800 (PST) Message-ID: <547CB956.5010702@gmail.com> Date: Mon, 01 Dec 2014 18:54:14 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: internals References: <003c01d00d6e$f4fd77c0$def86740$@tutteli.ch> <868FD3D8-4E80-46F4-872A-125D3FD8F40D@ajf.me> <547C991E.2070700@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Static classes (Was Abstract final classes) From: rowan.collins@gmail.com (Rowan Collins) Levi Morrison wrote on 01/12/2014 17:58: >> The only thing missing is a standardised, enforced, annotation on the class >> to declare that you are using this ability and instances will never be >> created. > Let's say a class has no members: what's the harm in instantiating it? > Sure, it logically doesn't do anything useful, but is this user error > such a big deal that we alter the language to disallow it? The same could be said of many function and class modifiers - they exist as self-documenting, mostly compile-time, assertions. There may not be a compelling reason to add one, but "the user's self-discipline should be good enough" isn't a very compelling reason not to. I do think the keyword should trigger simple enforcement, though, not automagically change the behaviour. static class Foo { function bar() { echo do_something_with($this); } } Much nicer (and just as easy) for that to give a compile-time error of "Static class Foo cannot contain non-static function bar" than for it to autoload fine, and then give a less obvious error when Foo::bar() is run (probably to do with a non-existent variable, since $this is always undefined inside a static function). Programmers, and automated tools, won't know about the "static class" annotation immediately, but hopefully already know what "static function" means. Note that this is the same as with "abstract function" vs "abstract class", only the other way around - adding an abstract function doesn't implicitly convert a class to be abstract, it refuses to compile if you don't explicitly do so. Regards, -- Rowan Collins [IMSoP]