Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79351 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42606 invoked from network); 1 Dec 2014 19:24:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2014 19:24:30 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.41 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.41 mail-pa0-f41.google.com Received: from [209.85.220.41] ([209.85.220.41:51321] helo=mail-pa0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F7/91-32869-D60CC745 for ; Mon, 01 Dec 2014 14:24:29 -0500 Received: by mail-pa0-f41.google.com with SMTP id rd3so11764433pab.0 for ; Mon, 01 Dec 2014 11:24:26 -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:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=uJcJzUBsGkemeOvdj7OaoytfdObAt3PZ6WNlUyQLm9g=; b=iE0IgbgQH1GRPVvW5MYSN0O9KrVgoEO2XkDXZI7uf8NsoI5aP9h6OHrtI4KdDiUAv7 Wf6UlY/klhLZxuarxyXvuYX8iSyHiAZJeh6vCkQLr4mfv1B4dINeeEsdSMwyunMyGwSx EPtRCirW/dOrxY//2Gb2mSESU7Z6a9piqDR/mntPvc4PSw/62TRXgGiGmCkvd8qmpz+G PQ6yRt6brdpCapqlcw0k0JLNWeuo5kpB+Oyui8MPCUQ8WaDNHvwThct09Rhjkc/LjY9D xsf9OhnA871bgcM/UhUsEbayPcilGi/XvrXliD+VX4AcvK7LvkYbbnFUdhbzZ/BFX2mx XCww== X-Received: by 10.70.90.11 with SMTP id bs11mr105710007pdb.16.1417461866562; Mon, 01 Dec 2014 11:24:26 -0800 (PST) Received: from stas-air.corp.wikimedia.org (tan4.corp.wikimedia.org. [198.73.209.4]) by mx.google.com with ESMTPSA id z5sm18152785pbt.89.2014.12.01.11.24.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Dec 2014 11:24:25 -0800 (PST) Message-ID: <547CA967.20607@gmail.com> Date: Mon, 01 Dec 2014 09:46:15 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Andrea Faulds , Robert Stoll CC: internals , guilhermeblanco@gmail.com References: <003c01d00d6e$f4fd77c0$def86740$@tutteli.ch> <868FD3D8-4E80-46F4-872A-125D3FD8F40D@ajf.me> In-Reply-To: <868FD3D8-4E80-46F4-872A-125D3FD8F40D@ajf.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Static classes (Was Abstract final classes) From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > (2) Add lexically-scoped variables, and allow normal global functions > to be closures. By this I mean we add something like JavaScript’s > `let` keyword that would make a variable that is unset when it falls > out of scope (end of a {} block, end of a file etc.). Then, we allow > normal functions to use the `use ($var)` syntax and close over > variables. That’d look something like this: > > let $x = 0; > function getCounter() use(&$x) { > return $x; > } > function incrementCounter() use(&$x) { > return $x++; > } > // since this is the end of the file, $x falls out of scope > This looks like you're trying to create a class without calling it a class. Now, I agree that not everything should be a class. But what you're doing - set of functions linked by common behavior and sharing a common state - is a perfect fit for something classes and objects are used in PHP. So why not just use them instead of inventing creative ways of doing the same but in more complicated way? Moreover, since your example is clearly not a singleton - it is hard to imagine any program that would have use for just one counter but never any more - it is a classic example of something that should be an object. It might be a wrong example, but I have hard time seeing any example of something that has a group of functions, bound by common functionality, has a shared state and still should not and can not be expressed as a class/object. That's literally what they are made for. Now, utility classes do suck, but they suck not because they do what you described - on the contrary, they suck exactly because they are usually a bag of random, unrelated functions bound by nothing but the common trait of "we don't have other places to put them in". But for that, plain old functions work just fine in PHP. -- Stas Malyshev smalyshev@gmail.com