Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31948 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51851 invoked by uid 1010); 27 Aug 2007 22:34:02 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 51836 invoked from network); 27 Aug 2007 22:34:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Aug 2007 22:34:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 38.99.98.18 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 38.99.98.18 beast.bluga.net Linux 2.6 Received: from [38.99.98.18] ([38.99.98.18:42597] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/E2-32031-A5153D64 for ; Mon, 27 Aug 2007 18:34:02 -0400 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id 9FCA391E308; Mon, 27 Aug 2007 15:33:59 -0700 (MST) Received: from [192.168.0.106] (CPE-76-84-1-170.neb.res.rr.com [76.84.1.170]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bluga.net (Postfix) with ESMTP id E814991E307; Mon, 27 Aug 2007 15:33:58 -0700 (MST) Message-ID: <46D351F5.8080806@chiaraquartet.net> Date: Mon, 27 Aug 2007 17:36:37 -0500 User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: Stanislav Malyshev CC: Dmitry Stogov , 'PHP Internals List' References: <000f01c7e871$9be827e0$6e02a8c0@thinkpad> <46D30EA2.7080406@zend.com> In-Reply-To: <46D30EA2.7080406@zend.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: [PHP-DEV] Namespaces and __autoload() From: greg@chiaraquartet.net (Gregory Beaver) Stanislav Malyshev wrote: >> > 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. This is a problem, agreed. > 2. All libraries having autoloaders would have to rewrite them to > support the new mode. This is not an issue - won't they have to support Class::Names::Like::This anyways? Backwards compatibility has already been broken. > 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. The problem is that with this autoload technique this code now throws an Exception rather than a Foo::Exception: Foo/Exception.php: Foo/Something.php: This would mean that all naming conflicts with internal classes must have a different import or be fully qualified. However, I wonder if using an import would be a clever way to get around the problem? Foo/Something.php: As I understand it, this would make the file act as if we had written it like: Foo/Something.php: If this is indeed the case, then it would satisfy my concerns with the patch and would simply be up to the documentation team to document this gotcha. Greg