Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97987 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74150 invoked from network); 27 Jan 2017 14:53:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jan 2017 14:53:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.44 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.44 mail-lf0-f44.google.com Received: from [209.85.215.44] ([209.85.215.44:34224] helo=mail-lf0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/F7-28703-CCE5B885 for ; Fri, 27 Jan 2017 09:53:01 -0500 Received: by mail-lf0-f44.google.com with SMTP id v186so163170240lfa.1 for ; Fri, 27 Jan 2017 06:53:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:subject:references:date:mime-version:content-transfer-encoding :from:message-id:in-reply-to:user-agent; bh=nGpmD6y7tz2yEXG+rBWO3pzN7r4f4yDN4OfSpM0Rgv4=; b=P1KTauQkHUI6YDImQoifDvI7wRJllf0+wUu6hCNIWn4YTpkeF1btAaJI1Iu3mlGtFE ELERBgznd/cthKTR7ibUwWbPeHn25ugwpm3hu0fSK/g574k21kLBRzboiR1GCyCmt+YQ iQiOlzFgVUpYsfBoLJ6XJYj1/KuQbqR6HCro+orMpGQ3WLnADgd0Z2l4k1kRpLginv02 4m2Z2fPDDQ4pgYO5MmjaavP2t1huAhM4X1F9pAwHRvgPmnd3iQiJ663P7aQWZaJlHeq+ KMJMFYzPo1i1lNPj7Ckw40oaAghxJDo7dweYBTan6u2bW6v+OxdBiwMR+Ol2GoLsiFvk zncA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=nGpmD6y7tz2yEXG+rBWO3pzN7r4f4yDN4OfSpM0Rgv4=; b=j6HwMW8QQ1Fok1AnnYWCTgT2nrdtyrm6ghadT/HLKRQYjUZl6a6aUYt2gpRMn56T6S vBFAEgO8VQ4uL3k6X9iSOdfXJpqX/U9R7OB4PjSpgrdATYTKuLKCQWNFOzPbnwEA0Sb7 UeC2K5AuYxshr14ybQM8DM5Hrk9vQ901WS3Rvd/lCgPYqiQoP0SA3deMaluTeerM6O4P UEoqAFMf+iO+WmF7BDXE/E6j4D61/BL03YPOD3Ok9IsOhSFF+o/bnLx8fDbNk4NQyspB J9bs6n0AjYtmiGrW6tuZOOPF5dYyjv+DYv9g7pEI8WvW6oRDSGmbLgBQJ+J7R2EzNN8Q pQUQ== X-Gm-Message-State: AIkVDXIiqDTZ2qsMJv5FzKCksLwVRYd0oZTd3mgrnQZOByCXZQ9CQh/6kOzSnmqwG65NGQ== X-Received: by 10.25.137.193 with SMTP id l184mr2467089lfd.31.1485528777118; Fri, 27 Jan 2017 06:52:57 -0800 (PST) Received: from nikita-work-box ([185.62.192.230]) by smtp.gmail.com with ESMTPSA id 9sm1360421ljg.33.2017.01.27.06.52.56 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 27 Jan 2017 06:52:56 -0800 (PST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "PHP internals" , "Rasmus Schultz" References: Date: Fri, 27 Jan 2017 17:52:22 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV] Not autoloading functions From: inefedor@gmail.com ("Nikita Nefedov") On Fri, 20 Jan 2017 10:04:44 +0300, Rasmus Schultz wrote: > Just a quick thought. > > Since the autoloading functions proposal is stalled, how about allowing > for > import of static functions instead? > > use function Foo::bar; > > bar(); // calls Foo::bar() > > There are two benefits to this approach: > > 1. There is immediate support for autoloading without any need for > adoption > or support in existing autoloaders. > > 2. Pseudo-namespaces (abstract classes with stateless static functions) > are > already widely practiced in PHP - a lot of existing code would be > supported > as is. > > The syntax when calling functions would be the same. > > If we had function autoloading, we would likely collect related functions > in a file anyway - putting them in a class instead gives more less the > same > exact result. > > The only drawback I can see, is the inability to import a whole set of > functions with one statement - but being explicit about external imports > is > widely considered best practice for classes and interfaces, so why not > for > functions. Yeah, it's a bit inconvenient, but at least we can move ahead > and leverage existing code without changes or BC breaks. It's not all > bad. > It's better than nothing perhaps? :-) > > Thoughts? Maybe we might think about modules this time? Lots of languages use this approach and they seem to be pretty happy with it. Here's how it could look like, very abstractly. I don't really see any big issues with the way how to implement it either. https://gist.github.com/nikita2206/2e4ab1b314e840f93ed75a0b88266d35