Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76215 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30298 invoked from network); 28 Jul 2014 07:42:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2014 07:42:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.219.49 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.219.49 mail-oa0-f49.google.com Received: from [209.85.219.49] ([209.85.219.49:57280] helo=mail-oa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/D1-26001-FEEF5D35 for ; Mon, 28 Jul 2014 03:42:39 -0400 Received: by mail-oa0-f49.google.com with SMTP id eb12so8149460oac.8 for ; Mon, 28 Jul 2014 00:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=tsq/Tjv8FN+XdL2dElMPzqbApSPkwsJ00VbMbxPxckA=; b=h1kuLIzBlrCG93j1Ml9uqbiNIHTJDY2FsIUxQW+gDyzxxu9EFFP9OEh/ISCX2nLgvk YY6ztFdcSzpldIFrDZoeNf9ZX7C9p00Bb5zq8j3AJeX1kR+tKkeEhEGEvAfXUIfeR89k I8+bW/HwIDLmSA6EWtIHnwtuZ3IrAh9UIlzSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=tsq/Tjv8FN+XdL2dElMPzqbApSPkwsJ00VbMbxPxckA=; b=TMg8inAf+6IzeE6ZSAKpYToi5eLNtWGp3Vvl0Y614Uqvyvb7DJT2tl6ryaeA2PmNfA u+A51+IAGsnm4BUVDXji8p7+sp0kqg8VGIuV3MPFo293AptDBVIxUGy9J/aEKsAoo3YD RrjEbiDA0yCXXWzcH03r9s8uze2WWBGdu1cPX+9xNHCKu7OAOd6tJPT9BCALEKWiGyhY HkK9rPR7wsymQfr33xRzymrDtduZSlPbB4njGLP8Z551MplmDtP9BR0SR3WGyTuzdixB o6AcrW9vObSfLZR4JWE+gq3CRTFs50mwL/PTMHtJ83Yum59BQATwoQpa5BvEiOa+jzoj ua8A== X-Gm-Message-State: ALoCoQki361HEOtahLhRtWmCnXQ8+JyjpKrxmdP+ZPUEmV4U/3HWztITSDlZshdu4fh0KnjyrsyZ MIME-Version: 1.0 X-Received: by 10.182.102.197 with SMTP id fq5mr45501234obb.3.1406533368481; Mon, 28 Jul 2014 00:42:48 -0700 (PDT) Received: by 10.202.75.205 with HTTP; Mon, 28 Jul 2014 00:42:48 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Jul 2014 10:42:48 +0300 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] "PHP" namespace? From: narf@devilix.net (Andrey Andreev) Hi, On Mon, Jul 28, 2014 at 5:58 AM, Yasuo Ohgaki wrote: > Hi all, > > Since we have discussion for Next PHP, "PHP" namespace discussion would b= e > nice > to have. > > Currently, PHP module functions/classes/interfaces are using global(root) > namespace. > If it is changed to use its own namespace, user space APIs may be changed > flexible and user controlled manner. Thus, PHP may have > > - Consistent naming > - Consistent parameter order > - Graceful function/class/interface deprecation > (We know what we should do for these, right?) > > without much compatibility issues. > > > "PHP" namespace may be used to provide PHP(and 3rd party) > functions/classes/interfaces/constants. > "PHP\Legacy" (or whatever) may be used for legacy > functions/classes/interfaces/constants. > > From PHP 5.6, userland function aliasing can be done with namespace. > Following code overrides existing function. > > use function \mb_strlen as strlen; > var_dump(strlen('=E6=97=A5=E6=9C=AC=E8=AA=9E')); > ?> > > Result: > int(3) > > It's good to use prefered API, but it requires "use" for every function > APIs to be overridden. > Note: Classes/Interfaces may override by "use" one by one also. > > With "PHP" and "PHP\Legacy" namespace, user may write: > > namespace PHP; // Use current PHP functions/classes/interfaces/constants > > // Code uses current API > ?> > > namespace PHP; > namespace PHP\Legacy; // Override with legacy PHP > functions/classes/interfaces/constants. > > // Code uses legacy API > ?> > > For compatibility, default namespace setting would be nice to have. > - None for compiled default > - "PHP" for php.ini-* > > Previous example codes became: > > // Code uses current API > ?> > > namespace PHP\Legacy; // Override with legacy PHP > functions/classes/interfaces/constants. > // Code uses legacy API > ?> > > Issue would be codes that assume PHP functions/classes/interfaces/constan= ts > are > defined in global(root) namespace. (e.g. \strlen()) This could be > workaround by allowing > "use" aliasing to global(root) namespace. (e.g. "use PHP\Legacy as \;") = In > this case, > current functions/classes/interfaces may stay in global(root) namespace. > (or "use PHP as \;") > > > Programmers may shoot their own foot by this. This is the trade off of > flexibility. > > Any thoughts and/or comments? > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net This would be a major BC break, that couldn't possibly happen in PHP 5.x and IMO is way too radical even for PHP 6/7. I generally hate to see statements like "this is not the PHP way", but that's exactly the case with your proposal - it _enforces_ a more strict way of programming. One must absolutely not be required to use namespaces for everything. Cheers, Andrey.