Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94533 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3500 invoked from network); 17 Jul 2016 18:21:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2016 18:21:22 -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.42 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:37403] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/69-31884-0ACCB875 for ; Sun, 17 Jul 2016 14:21:20 -0400 Received: by mail-wm0-f42.google.com with SMTP id i5so89580691wmg.0 for ; Sun, 17 Jul 2016 11:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=13N4RpC4bOBw2oTu1zldMZKUKk/fPMTyh+5+VhNohwY=; b=pNtC6L6uBofV/c2Vo405hyR2YVntMaEfXGXf4die7HOg6cV55sS3rDAjjhx6+tc2CS cKvAs/gLQAG5qGceOwCno5BK3xumnnfHW0sSg9GwT/0YbsHbGlKJMWcM/lwbI+lxxFb8 uHh/ZPYwAwK9tmKzL+QgRcdulyUudr5d+txpvh8GKo7gDF8miMt/lMirlqyMVAGw760U T0SB+06AJ8+M+P/GGu1gqzxJSRZ9sIfKJUoMdmhjzlE+PJXd32IXfULkBNSmgGH80S0o VHmLLwjfGr2mnDfeDT+/PDmtacUT7iRi6yq9IzAHwbceCKtVwjCA+odfHyoxZV4Ej1sI uSSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=13N4RpC4bOBw2oTu1zldMZKUKk/fPMTyh+5+VhNohwY=; b=A8KRBbMRXuzGWkqz4/ovycHrJM5RcwbrQ++M5WaJCH74dhEhYb3LOtc1m38qIdNPnN TjhO/qAzOogFU4kpddq23+3hF9/OcZT0TWNHCqCy5/HncgqUIcDacXGP12FPeZPGxdfH vIYPsCbuv0kCkBFZcTmvh6vpaPk8m9VtNDvBRFZkbjEMvBSCOJ196PuX7xEb0JzhCizE tPxArnMpsWohlQsJGgaIvvLorWspzsj9daZzu7RXGZgQLU2hm2E9Pv9QdW+oTIeZRdSe hQE35E9khCSa8HGGiI7yzTFdwNU1NMHMoj5jMlFuCjRLWLe8JiIPhow1Ty+0GiCkivQc pHBw== X-Gm-Message-State: ALyK8tIRF1E0UUcmTBehflf9SUsJ5+gXRJ6THq4WoTtHvuvd+xjK6PdIQICSFDVHtP2A+Q== X-Received: by 10.28.187.67 with SMTP id l64mr30930098wmf.11.1468779677568; Sun, 17 Jul 2016 11:21:17 -0700 (PDT) Received: from [192.168.1.5] ([95.148.161.240]) by smtp.googlemail.com with ESMTPSA id x62sm10279102wmf.13.2016.07.17.11.21.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jul 2016 11:21:16 -0700 (PDT) To: PHP Internals Message-ID: Date: Sun, 17 Jul 2016 19:21:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Idea: Function autoloading using dummy namespaces From: rowan.collins@gmail.com (Rowan Collins) Hi All, In the discussion of escaping mechanisms, it's once again come up that functions lack autoloading, and thus are hard to work with in larger code bases. Previous solutions to this, most notably Anthony Ferrara's very thorough RFC [1], have looked at adding new modes for the existing autoload functions, or new functions alongside, to specify the type being autoloaded. A common response is that you can just use a class with static methods, and thus leverage the existing autoload mechanism. But the introduction of "static class" or "abstract final class" was rejected [2] in part with the opposite justification: that you shouldn't need a class to hold static methods now that we have namespaced functions. How about an alternative approach where a function inside a namespace can be autoloaded using the existing callback, by using a reserved namespace segment? So to autoload function "foo\bar()", the engine would construct a string like "__function\foo\bar" or "foo\__function\bar", and pass that to the registered autoloader stack. This shouldn't result in errors or misbehaviour from existing autoloaders, it just won't find anything to load. An autoloader that knows how can then use the namespace path to determine what to load, probably something like "src/foo/functions.php". The focus on namespaced functions reflects the fact that one-file-per-function is rare and somewhat unwieldy, so a call to load "__function\foo" is unlikely to be that useful in practice. Note that, like many previous proposals, this could apply to namespaced constants, too, using a token such as __constant. Any thoughts? Good idea, horrible idea? [1] https://wiki.php.net/rfc/function_autoloading [2] https://wiki.php.net/rfc/abstract_final_class Regards, -- Rowan Collins [IMSoP]