Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32274 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78853 invoked by uid 1010); 11 Sep 2007 21:29:00 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 78828 invoked from network); 11 Sep 2007 21:29:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Sep 2007 21:29:00 -0000 Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; 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:54784] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/49-33962-B9807E64 for ; Tue, 11 Sep 2007 17:28:59 -0400 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id CD9A4C0D6DD; Tue, 11 Sep 2007 14:28:54 -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 E8E99C0D6DA; Tue, 11 Sep 2007 14:28:53 -0700 (MST) Message-ID: <46E70959.3070001@chiaraquartet.net> Date: Tue, 11 Sep 2007 16:32:09 -0500 User-Agent: Thunderbird 1.5.0.13 (X11/20070824) MIME-Version: 1.0 To: Stanislav Malyshev CC: 'PHP Internals' References: <46E5D163.4050800@zend.com> In-Reply-To: <46E5D163.4050800@zend.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: multiple namespace per file From: greg@chiaraquartet.net (Gregory Beaver) Stanislav Malyshev wrote: > Hi! > > Following the feedback from the community, we (mostly me and Dmitry) > tried to find a good model that would allow multiple namespaces per file > without running into too many problems and complications, and would > allow to bundle multiple namespaced files together without > modifications. It looks like it is possible to do, but only under the > following condition: the file can have multiple namespaces, but if the > file has namespaces, then it can have no code outside namespaces. > > For example, this would work: > namespace A; > class X {} > namespace B; > class Y {} > > This would not work: > class X {} > namespace A; > class Y {} > > This would not work either: > require 'foo/bar.php'; > namespace A; > class X {} > > This however would work: > namespace A; > require 'foo/bar.php'; > class X {} > namespace B; > class Y {} > > So, for the people that wanted multiple NS per file, would such solution > work? Hi, This explanation could be slightly clearer. The most important thing to realize is that allowing multiple namespaces per file is not an attempt to allow a development paradigm where multiple namespaces exist in the same file. Rather, the goal is to allow multiple *files* to be combined into a single file. A benchmark devised by David and modified by me proves that the performance difference between separate files and a single file containing the same stuff is at a minimum 10%, and can be up to 30% difference even with APC and apc.no_stat=1 Allowing multiple namespaces per file should instead be thought of as "allowing several files to be cut/pasted into a single file" and not as a new way to develop in PHP. The proposed syntax is in fact somewhat difficult to read, which discourages development along these lines, but it does make it possible to combine files in a performance-hungry setting. Once the syntax is thought of along these lines, it makes a lot more sense. It's basically one-namespace-per-file but PHP allows you to virtually combine files so that at each namespace declaration, the imports are reset. Greg