Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94980 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32168 invoked from network); 9 Aug 2016 21:26:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2016 21:26:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wm0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:38369] helo=mail-wm0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/09-03404-09A4AA75 for ; Tue, 09 Aug 2016 17:26:40 -0400 Received: by mail-wm0-f41.google.com with SMTP id o80so62458476wme.1 for ; Tue, 09 Aug 2016 14:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:references:from:to:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=+GvYkngGfiQ+tQiITIr+whDqmONhVcgE6TMjJXCNyBg=; b=xCXOjGsUON2SRGXg0QRyCDJ60ChvIi532+e7A10IEjBiFejtFEAO4/VkmCe/ayr3OA TNedCLHKubbinrCiPdXBWe6qGunlvsYYxCjyAFnUHLfhz4i5qxPXThsTYLAbrZLkDHhv ww6AmAGbboejAidYuH7pBBW/2JOCZ00vWmDhlAj8bAzQxR1fL60oDLjZ1McoUYDv07fH op0WwyxNmt9GJF+OBA+ogkYDKmUESpHjj57K+7Lhh49Bgucla3EdMYUZlhwm7B79h12H mD3x6saA5hSj0D9sUH24pEKi9KI0uzdovZWIm1E4XY9Qz+3BTJQE2wZ/en1b7rJKT2Ko 8zMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:references:from:to:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=+GvYkngGfiQ+tQiITIr+whDqmONhVcgE6TMjJXCNyBg=; b=FaCIMqkYRo5uaCJiDaITixuZ8qsvoDxACofvdq/NGbQMwjgDI9dwvhfqsYRk02DEJV bFpxHlrI24j7A+PH9BfalMH1cV09FjgxnhLtiJz/KimsNX8NEcx/GwzoI76ZBec+NSmg 8aRA6FftMXko79tLKX5L/IyREZNeBuNEySkfcTyrUPUuhqGsbBP6opuQ40MEhpFSGMQT 5t3YjHNR90UZ8nH7OkRWU66M7tcKjY/08GXJFl9Dzaym/V0NCcqgdq6/y3u0MVmbTirO UvBgMKW67LyYYVC1FDGGiuke3q9lO43uwWA129ZYGxqIuBqoydEDWxrW79+4OTGcj+gp 8pSw== X-Gm-Message-State: AEkoouvpiftZjLbodbJ5vA8CrPbGKs+g/35ZgJyl4LWvlRNbHskwXpA40rZv+Y8crCMncA== X-Received: by 10.28.228.132 with SMTP id b126mr25362895wmh.93.1470777997568; Tue, 09 Aug 2016 14:26:37 -0700 (PDT) Received: from [192.168.1.5] ([95.148.161.240]) by smtp.googlemail.com with ESMTPSA id xa2sm39803360wjc.0.2016.08.09.14.26.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Aug 2016 14:26:37 -0700 (PDT) References: <33781781-2a63-78c1-68a1-9e19ad720d8d@gmail.com> <1d89ec68-de5e-2670-aed1-f12872c073c3@gmail.com> <615f02b9-0621-2e7a-bec9-af4e342529b2@gmail.com> To: internals Message-ID: <0d55f224-201e-2273-8faa-296122320e19@gmail.com> Date: Tue, 9 Aug 2016 22:26:32 +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 09/08/2016 18:44, Rasmus Schultz wrote: > On Tue, Aug 9, 2016 at 6:17 PM, Rowan Collins wrote: > >>> >>In other words, calls to substr() does not trigger the resolve - a >>> >>statement like "use function substr" on the other hand, does. >> > >> >Ah, I see. The problem with that is, you still have to explicitly list every >> >function you're going to use, so you might as well just use require_once, or >> >call "load_function('substr')" directly. > Well, no - there is still the issue of file names and paths becoming a > dependency, besides issue of having to locate the file in the first > place. Sure, there is a small advantage over raw require statements, because you're wrapping the file-location logic in a function, which can be a bit more flexible. But that doesn't actually need the engine to do anything special: Proposed: function autoload_function($name) { require_once FUNCTION_ROOT . str_replace('\', PATH_SEPARATOR, $name) . '.php'; } register_function_autoloader('autoload_function'); use function Acme\Util\foo; // calls autoload_function('Acme\Util\foo'); use function Acme\Util\bar; // calls autoload_function('Acme\Util\bar'); Current PHP: function load_function($name) { if function_exists($name) return; require_once FUNCTION_ROOT . str_replace('\', PATH_SEPARATOR, $name) . '.php'; } load_function('Acme\Util\foo'); load_function('Acme\Util\bar'); All we'd really gain is a standard "name" for load_function (i.e. the "use" keyword), and I guess a built-in registry for chaining multiple callbacks together when you run it. Regards, -- Rowan Collins [IMSoP]