Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56269 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20836 invoked from network); 11 Nov 2011 03:31:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Nov 2011 03:31:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:57781] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 08/66-17932-6179CBE4 for ; Thu, 10 Nov 2011 22:31:35 -0500 Received: by gyg13 with SMTP id 13so2777257gyg.29 for ; Thu, 10 Nov 2011 19:31:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=dnNkUs72bIdhp3fl3ryG6VXFGhL6nzaYaLMQHdIl87A=; b=Vt1gz1qNamwkApODtO5SFNK7uX/WdIhKSLzvJ6N2y4HpoJfIGHjqy5NvuHNG6AUNuX 74OtGXfozGHFb2pOkhAo6mn2c4rKtB1q5JlkISr8rMukueQjhuYU5KuK0ZmQuluWL78e tL297nV0VbAyrusPjERqVm95NFpZ38NS3m6Ec= Received: by 10.68.32.99 with SMTP id h3mr20112778pbi.38.1320982292163; Thu, 10 Nov 2011 19:31:32 -0800 (PST) Received: from [192.168.1.181] (static-93-136.net2000.com.au. [203.32.93.136]) by mx.google.com with ESMTPS id b8sm26555272pba.16.2011.11.10.19.31.29 (version=SSLv3 cipher=OTHER); Thu, 10 Nov 2011 19:31:31 -0800 (PST) Message-ID: <4EBC9710.5010807@gmail.com> Date: Fri, 11 Nov 2011 14:31:28 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "guilhermeblanco@gmail.com" CC: Anthony Ferrara , PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Re: SPLClassLoader RFC Thoughts And Improvements From: davidkmuir@gmail.com (David Muir) On 11/11/2011 01:31 PM, guilhermeblanco@gmail.com wrote: > Hi Anthony, > > Thanks immensely for your input. > Without such action, it's extremely hard to improve the RFC. =) > Awesome action from your side. > I'll place my comments inline. > > On Thu, Nov 10, 2011 at 1:26 PM, Anthony Ferrara wrote: > ...snip... >> b) The code that includes the file should be changed to require_once >> to eliminate including the same file twice when different classes map >> to the same file. For example, this should not fail (assuming both >> classes are not in the same file): >> >> new \Foo\Bar\Baz; >> new \Foo\Bar_Baz; >> >> Both map to the same file, but are distinct classes in PHP. >> By changing it to require_once, it'll realize it already included the >> file and then skip over that and let another class have its shot. >> > Actually they do not map the same file. Here is the path of each one: > new \Foo\Bar\Baz; => [path]/Foo/Bar/Baz.php > new \Foo\Bar_Baz; => [path]/Foo/Bar_Baz.php > > You may now be in doubt if PEAR1 style is supported. Yes, it is. The > point is that code detects for the presence of namespace separator and > if it is found, it considers the namespace separator as directory > separator; if not, it considers the "_" char as directory separator. > We decided that because PEAR1/Zend1/Doctrine1/Symfony1 (and many > others) would not be supported if we didn't do that way. It's the > solution for BC. Since most of the mentioned ones are already in > another major version, consuming PHP 5.3 namespaces, then the default > behavior would work nifty. =) This is news to me, and even the RFC states: Each “_” character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The “_” character has no special meaning in the namespace. I believe you're confusing it with the namespace portion: new \Foo_Bar\Baz; => [path] /Foo_Bar/Baz.php in which case the _ is retained. Otherwise: new \Foo\Bar_Baz; => [path] /Foo/Bar/Baz.php new \Foo_Bar\Baz_Waz => [path] /Foo_Bar/Baz/Waz.php If what you are saying is true, then the RFC is incorrect, and should be updated to included the correct rules. > > Regarding the require_once change, it's not really needed. The reason > is because class loading would never be triggered again if the > class/trait/interface is already loaded. The require_once is extremely > slow than require due to this check. > But I really don't have strong feelings to change that is many people > find it necessary. That was true 6 years ago. Benchmarks from 4 years ago, it was the other way around. Has it flipped back again? ...snip... >> 4. The RFC should avoid implementing any pattern or style that may >> make future feature addition difficult or pose risks towards such. An >> example would be implementing an interface for the autoloader which >> defines something like load($class). The problem there is that if >> function autoloading is added, the interface won't be able to support >> it. So it's stuck in a hard place between changing an implemented >> interface (which will bork code significantly on update) and adding a >> new interface (which would be the lesser of evils, but would just add >> to the deprecated cruft). > OO theory defines that whenever you want to have a contract to be > followed by any implementation, an interface is required. > The contract is something useful that enforces that way you receive > would have at least what it was expected/used internally. > So, if we agree in the future that the chosen implementation would not > contain the methods ->register/->unregister, and spl_autoload_register > would accept SplAutoload instances, then the contract is more than > required. > Regarding the function autoloading, as I discussed previously, it is > invalid in this paradigm. > I don't see how the contract would change in the future. But the only contract that is needed by spl_autoload_register is the load method. The register and unregister methods are not needed by any other entity that I am aware of, and are only there as convenience methods for the user, and therefore don't belong in the interface for a generic autoloader. A second interface could be added for self-registering autoloaders, but that begs the question, why should an autoloader know how to register itself with a particular loading stack (sure the spl autoloading stack is the only one we have, but still...)? There's no discussion in the RFC showing why those methods should be part of an autoloader interface. The same applies to the setMode() and add() methods. What contract are they fulfilling? Cheers, David