Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94958 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39888 invoked from network); 8 Aug 2016 22:04:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2016 22:04:07 -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.45 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.45 mail-wm0-f45.google.com Received: from [74.125.82.45] ([74.125.82.45:37750] helo=mail-wm0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DF/9B-33134-6D109A75 for ; Mon, 08 Aug 2016 18:04:07 -0400 Received: by mail-wm0-f45.google.com with SMTP id i5so167855368wmg.0 for ; Mon, 08 Aug 2016 15:04:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=omvS6TU254acs2IVR/DQt27mJAY/YyVyyMuHDUtVWoo=; b=xI7y2WuUM84R3hMIbjePsIrxEDLWsQQnfAIbvgjZW2Q8CFpGzTlCzUhrkPr57mwF+w LEPBW8mzfe1pmE5UI2Wq4y17b7Rme9ikYQDNE/HgjP0rl3XrsHlqVZaOApBLZV7BfTih BATGRForRs+vIGgCWMFAUsJx6msJq6soLhzdt5xzxHxPCrSseIpvOlr5TyMxzfizQE+w nsg2j1JBisuqYndGUvhRX4x5httaLLEN6OAZESKR5f7pnj3y6+4m00wIqAEULdVtUAAx DUJgBpW0HOALRAGT8KOncuIB1332/xTMtyEDbt21lCku2WLzCdJKnydmDU9M/IQo5DsG ZqsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=omvS6TU254acs2IVR/DQt27mJAY/YyVyyMuHDUtVWoo=; b=bB23x9ejhykA5Or3aS1PPqA5PilBh2QzD7DCX/j4Ri6LsL3CFsHZhFBulPxLZ/cKyG z0qigjaeHZVmr1OCpvnMLIPGOzrq7FdfUaWVb92gJClNK32Li+HaGpqaY86XPmQ6jknW MEIRfw9MHWgRf/QSTlyChzDhp3srLYMTB1acMM00lSujwGYHa2/4b+l53f30dnjQGyMM WBLxhlPpJGDxHCzePtDl9Y9xG1PKLzQ18fok+QNWeqt3YqMgd/N23n2DGHW3xMaD5drM pkIKzwweTHHDXgLWgZiJCoPqBcr9AGGiNg3RJleVWsU6k6og838vZXLu2L2jkpSR4iLU /phw== X-Gm-Message-State: AEkoouvXlFwYdagCIIpaRKuQg64KQjoUnNLUi0b6Abu+yxrswAqv2QSt4IKfgd1aRWmYuA== X-Received: by 10.194.7.100 with SMTP id i4mr96067356wja.154.1470693843521; Mon, 08 Aug 2016 15:04:03 -0700 (PDT) Received: from [192.168.1.5] ([95.148.161.240]) by smtp.googlemail.com with ESMTPSA id t188sm162622wme.19.2016.08.08.15.04.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Aug 2016 15:04:02 -0700 (PDT) To: internals References: <33781781-2a63-78c1-68a1-9e19ad720d8d@gmail.com> <1d89ec68-de5e-2670-aed1-f12872c073c3@gmail.com> Message-ID: Date: Mon, 8 Aug 2016 23:04:00 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Function auto-loading From: rowan.collins@gmail.com (Rowan Collins) On 08/08/2016 21:15, Rasmus Schultz wrote: > A function resolver would simply need to return a callable: > > register_function_resolver(function ($name) { > if ($name === "html") { > return function ($str) { > return htmlspecialchars($str, ENT_HTML5); > }; > } > > if (substr($name, 0, 5) === "iter\\") { > require_once VENDOR_PATH."/nikic/iter/src/bootstrap.php"; > return $name; > } > }); > > This mechanism is probably a lot easier to explain and understand - > and works equally for global or namespaced functions. I don't quite follow what you're suggesting here. When does this "function resolver" get called? Why does returning a callable rather than just defining the function help with the problems we've been discussing? > Okay, so it doesn't deal with namespaced constants, and maybe this is > me being opinionated, but who's going to import constants one by one? > Constants are usually better off grouped together in a class. Although > I don't suppose there's any reason this concept couldn't be expanded > to work for constants as well, for completeness at least - though I > have doubts that very many people would care... It's not a case of importing constants - or, in most cases, functions - one by one. As I've mentioned a couple of times, an RFC on static classes [https://wiki.php.net/rfc/abstract_final_class] and various similar discussions are frequently met with "you shouldn't be using a class to group static items, use a namespace instead". For that we need "namespace autoloading", which in practice means autoloading any of the items you can put in a namespace. We can already autoload classes, so that leaves constants and functions. Regards, -- Rowan Collins [IMSoP]