Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62901 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85746 invoked from network); 7 Sep 2012 21:52:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2012 21:52:11 -0000 Authentication-Results: pb1.pair.com header.from=markg85@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=markg85@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: markg85@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:55383] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/13-65063-A8C6A405 for ; Fri, 07 Sep 2012 17:52:11 -0400 Received: by lbbgp3 with SMTP id gp3so130653lbb.29 for ; Fri, 07 Sep 2012 14:52:07 -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=GKE4TDwTXm5t9HLAKI1cvUU7i7ry7HeA7AnrHjw6JKA=; b=KBqWuEiX9ylH1AbGdGUpT27IOs3+SaNo3ja62GLHLaA5uRqx3kGYPX50t/mqP+17Kg zzzGM/ckvqW5GfoGkfSFy7caw3UnlDZQFusNyKMwzLtRlkaLtCmwzvCTHbhSIMuht0je CIasiLuojmlz/u16Q/5QYSgv/f2K2E73tSJGmeR0Hw81lL7MT+I8LfB+ZRlLGSTE9ulm ZByYxeKis5bZ4PaQbtWghJy+gtmN8PlxeA5ZYuG3X/1wKBwVo1VwODcPdfMnBBYcgwBO dViU2+ZQGcIeHW30aeo02TewhMVbfXq2MRJRZG2/mElrM++eGoChN7BuSU/z4jK03Wd+ ciVA== Received: by 10.112.45.72 with SMTP id k8mr2612353lbm.57.1347054727334; Fri, 07 Sep 2012 14:52:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.114.92.9 with HTTP; Fri, 7 Sep 2012 14:51:47 -0700 (PDT) In-Reply-To: <504A3CFE.6050307@sugarcrm.com> References: <504941BE.30102@sugarcrm.com> <50494740.6030205@sugarcrm.com> <504992B8.9050700@lsces.co.uk> <504A3CFE.6050307@sugarcrm.com> Date: Fri, 7 Sep 2012 23:51:47 +0200 Message-ID: To: Stas Malyshev Cc: "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Why are the PHP namespaces different compared to C++? From: markg85@gmail.com (Mark) On Fri, Sep 7, 2012 at 8:29 PM, Stas Malyshev wrote: > Hi! > >> Back on the namespace topic. I won't judge on anything, but i know >> namespaces from c++. I understand that PHP isn't a compiled language >> and quite frankly that doesn't matter at all. What does matter is that >> PHP uses the name: "namespace" which C++ obviously had earlier. > > Here is something that I would like to emphasize. There's no "one right > way" to do namespacing. And while PHP borrows a lot from other > languages, it was never promised or guaranteed that PHP would work > exactly like C++ or Java or Python or Ruby or any other language. If it > makes sense for PHP, it is taken in. If it's not, it is not taken. > > In the case of namespaces, we needed to solve a particular problem of > PHP - global namespace pollution and people inventing super-long really > tedious names to deal with it. Moreover, it is in general *exactly* what > namespaces are solving in each language. Namespaces were designed and > implemented to solve this particular problems, while keeping all other > parts of PHP working properly. > >> Naturally someone that knows both languaes (c++ and php) simply assume >> that a namespace in php probably works the same as those in C++. If >> that's not the case then it shouldn't even carry the "namespace" name. > > I couldn't disagree more. Namespace is a generic term, not belonging to > C++. PHP is not some offshoot of C++ that is required either behave like > C++ or stay away from it. Again, if it made sense in PHP to implement > *generic* concept of namespaces in a *particular way* that C++ does it - > we might do it. But it didn't, so we didn't. We have no responsibility > and no obligation to make implementations of generic concepts match > those in other languages or invent awkward names for those if they do > not. There's a value in behaving like other languages, but it only goes > so far. > Namespaces in PHP are as valid implementation of namespacing as those in > C++, they are just different. You came to it with prejudices about how > they should be working, these prejudices proved to be wrong, now you > know more and you continue to be more productive. This is natural and > happens to many people (myself included) quite often - one assumes > something, one is sometimes right and sometimes wrong. If one is wrong, > one corrects the mistake and becomes wiser. However I can't understand > how it makes sense to blame the language for not matching somebody's > personal background and prejudices. > >> To me this namespace in php stuff just looks like and alias. So why >> isn't it named as that: "alias"? I do not want to question the ones >> that implemented namespaces in php, but i do think that the name >> itself is at the very least confusing. > > It's not an alias. Aliasing is a part of it, but not the whole. > Declaration and the beginning of the file saying "alias My\Database" > makes little sense, declaration "namespace My\Database" makes great > sense - it shows that the file belongs to namespace My\Database, with > all consequences of that. > >> Also, lets keep this discussion polite people. I'm not here to smash >> toes. All i would like to know is the reasoning behind the above and > > I think I have explained the reasoning - specifically, why we have no > global imports - in my previous emails, but if you still have something > unclear, you are welcome to ask. It would make me happier though if you > tried to read through the archives where namespaces were discussed and > see all those arguments so we won't have to repeat them again, even > though I understand that nobody really does that :) > >> if there is any intention of changing the namespaces to be more c++ >> like. > > I would evaluate the chances of it as very small and I would be in a > very vocal and active opposition to that. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 Oke, it's clear to me now. I understand why PHP decided to do it this way (preventing global scope pollution). I don't agree on that, but it's nice to know the reasoning behind it. Guess i just have to live with it ^_-