Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31941 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49973 invoked by uid 1010); 27 Aug 2007 17:49:31 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 49955 invoked from network); 27 Aug 2007 17:49:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Aug 2007 17:49:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.114 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 63.205.162.114 unknown Windows 2000 SP4, XP SP1 Received: from [63.205.162.114] ([63.205.162.114:23212] helo=us-ex1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/C2-30013-8AE03D64 for ; Mon, 27 Aug 2007 13:49:31 -0400 Received: from [127.0.0.1] ([192.168.16.180]) by us-ex1.zend.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 27 Aug 2007 10:49:25 -0700 Message-ID: <46D30EA2.7080406@zend.com> Date: Mon, 27 Aug 2007 10:49:22 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Dmitry Stogov CC: 'PHP Internals List' References: <000f01c7e871$9be827e0$6e02a8c0@thinkpad> In-Reply-To: <000f01c7e871$9be827e0$6e02a8c0@thinkpad> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 27 Aug 2007 17:49:25.0684 (UTC) FILETIME=[9BBADF40:01C7E8D2] Subject: Re: [PHP-DEV] Namespaces and __autoload() From: stas@zend.com (Stanislav Malyshev) > namespace Foo; > throw new Exception; > > In this case PHP first looks for Foo::Exception and only then for internal > Exception, but the first lookup may call __autoload (or corresponding SPL > functions) and it can emit error or throw exception. > > The patch provides an additional boolean argument to __autoload() that say > if class is really required. In case if it false, user code shouldn't emit > errors or throw exceptions. There's two problems here: 1. On each access to internal class, like Exception, SPL classes, DateTime, reflection classes, etc. - we'd have call to autoload and subsequent disk access, maybe more than one if we have include path. Performance of it would be awful. 2. All libraries having autoloaders would have to rewrite them to support the new mode. I would propose different solution. When we have unresolved unqualified name, we do the following: 1. Check if we already know such class in namespace at compile-time. If so, it's resolved. 2. If not, will be resolved at run-time. 3. At run-time, check if we know such class in namespace now. If yes, it's resolved. 4. If not, check if we know internal class with such name. If yes, it's resolved to internal class. 5. If not, try to autoload this class. If autoloading fails, it's the undefined class error. This rule is a bit more complex, but allows to resolve common cases without extra filesystem accesses and allows to keep autoloader without modification. Comments? -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com