Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62885 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2482 invoked from network); 7 Sep 2012 00:49:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2012 00:49:36 -0000 Authentication-Results: pb1.pair.com header.from=g.b.yahav@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=g.b.yahav@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: g.b.yahav@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:49437] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/B1-03079-F9449405 for ; Thu, 06 Sep 2012 20:49:36 -0400 Received: by vbbfs19 with SMTP id fs19so2393415vbb.29 for ; Thu, 06 Sep 2012 17:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=bnNDd80hk4+nhpqho/A73t4I4aeN9yuFJa4S6sSsIM0=; b=yL1S9vXoc8J0dQJWIcrVj5v0bu8F8Hg3VtMSsmsq1/xPlrgwsyLlWuUo3tIgu1QHU/ BuENRcTwqve2MZhI27nA0qp4U54VoetL2JLYm97L8MbrucV6ALo8qTrPi+FUQoCGhoOQ WB8Ah3UafjuAuHx33IgAEeIuo6flEQRZt+hsZIjlYrOrhezBjXGsi1UnUftGl4/yxuN0 QpK5I5U9TKcfFFwt6galJmb2iwemhi85QJ4AzWS4W9kBcc7s/UHbQb67Ue0DLA2DY7tc rMpYTLosvuqNhRC4J9msmSdEbi5BSNtRZqr9oq6BZYkcmWy3wrSq5cWQMi3P/RYTBo/i P2NA== Received: by 10.52.92.98 with SMTP id cl2mr4009123vdb.101.1346978973043; Thu, 06 Sep 2012 17:49:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.0.69 with HTTP; Thu, 6 Sep 2012 17:49:12 -0700 (PDT) In-Reply-To: <504942C9.6050106@sugarcrm.com> References: <504942C9.6050106@sugarcrm.com> Date: Fri, 7 Sep 2012 03:49:12 +0300 Message-ID: To: Stas Malyshev Cc: Mark , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=20cf307f3144354d5f04c911fba4 Subject: Re: [PHP-DEV] Why are the PHP namespaces different compared to C++? From: g.b.yahav@gmail.com (Yahav Gindi Bar) --20cf307f3144354d5f04c911fba4 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Sep 7, 2012 at 3:41 AM, Stas Malyshev wrote: > Hi! > > > How about adding ability to import the entire namespace? > > This option was explicitly excluded because this defeats the whole idea > of having namespaces - i.e. having names to live in different spaces - > by explicitly bringing unknown set of names into global space. If you > allow global import, then you do not know which any of the names comes > from - it can come from any of the set of imported namespaces, or be > just global - and you have absolutely no idea about it and no way to > avoid conflicts. And all that to save you three keystrokes so you could > write DbConnection and not Db\DbConnection? Definitely not a good idea. > Current implementation makes it clear where things come from and avoids > naming conflicts, while still allowing you to use short names instead of > long and painful ones. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > That's true, but we do got the ability to import only one class from given namespace and classes aliasing so we can, for example, do something like: namespaceClasses.php namespace MyNamespace; class Foo { } class Bar { } class Baz { } use \MyNamespace\* { Foo as F Bar as B }; Then - the Foo and Bar classes will be F and B while Baz and any other class remain Baz. I do understand the point of conflicts, but I think that we should give the programmer the ability to decide whether to import specific class or the entire namespace. Other option I've thought of is to declare rules for importing as keywords or even a function that can import the namespace with given conflict rules for example use \MyNamespace\* noconflict; or even import_namespace('\MyNamespace', NS_AVOID_CONFICT); or something like that, though I think that a keyword allocated only to that propose is definitely not good approach... --20cf307f3144354d5f04c911fba4--