Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76221 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42588 invoked from network); 28 Jul 2014 08:50:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2014 08:50:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=petercowburn@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=petercowburn@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.52 as permitted sender) X-PHP-List-Original-Sender: petercowburn@gmail.com X-Host-Fingerprint: 209.85.192.52 mail-qg0-f52.google.com Received: from [209.85.192.52] ([209.85.192.52:58765] helo=mail-qg0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 10/14-26001-ABE06D35 for ; Mon, 28 Jul 2014 04:50:03 -0400 Received: by mail-qg0-f52.google.com with SMTP id f51so8094072qge.11 for ; Mon, 28 Jul 2014 01:50:11 -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=S1A7j75n+AcQK6v20m8zY2GDiPF+QuHGVIMB087MwGY=; b=y0RNXwu9NxGSSoqf2kxdt+EJrAkU53JUo8NLX1+hMT4Cou+e66lEBNC3TFu97ljbPK aIfl5GHXWUOCfKkY/18mxmWnHY1exmL8hhlOASkwr4a5wkmWBuiaRAy22gktA0QFyckP sdkfKIl9w3LedQj0QMC5hB6uJCIzPg1sSKmWfYBK4h4HmbUDZCc4jehuGTp/xckpp8l6 liQgU9euUJLP01rZ9VQfeuAlJWCnl6wKB6WcDVhTxHw6jiyB18gd7s9IR23X9XkO/0wb YUIhfI1eN5I/gy6WSrJI8QHlLMoDFtgKYuRRsx7vycfudbLpNdjtPDb+KdKpuBNovF15 QXMA== X-Received: by 10.140.31.246 with SMTP id f109mr57414323qgf.8.1406537411381; Mon, 28 Jul 2014 01:50:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.96.45.229 with HTTP; Mon, 28 Jul 2014 01:49:31 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Jul 2014 09:49:31 +0100 Message-ID: To: Ferenc Kovacs Cc: Yasuo Ohgaki , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a113a9556c4d22204ff3d020d Subject: Re: [PHP-DEV] "PHP" namespace? From: petercowburn@gmail.com (Peter Cowburn) --001a113a9556c4d22204ff3d020d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 28 July 2014 09:22, Ferenc Kovacs wrote: > On Mon, Jul 28, 2014 at 4:58 AM, Yasuo Ohgaki wrote: > > > Hi all, > > > > Since we have discussion for Next PHP, "PHP" namespace discussion would > be > > nice > > to have. > > > > Currently, PHP module functions/classes/interfaces are using global(roo= t) > > namespace. > > If it is changed to use its own namespace, user space APIs may be chang= ed > > 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/constant= s > > > > // 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/constants > > 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 > > > > hi, > > I think it would make sense to announce that the php namespace is reserve= d > for internal use, but I don't think that we are ready for moving everythi= ng > under namespaces. > For what it's worth, the manual already states that the "php" namespace is reserved for us.[1] > The way we currently implement namespaces can't support wildcard imports = so > the migration for project would be pretty tedious, finding and replacing > every occurance of a global function/class or use-ing every function/clas= s, > etc. > namespaces has a bit clunky way of supporting constants: define always > assumes global ns(and the const syntax only allows scalar values so it > isn't always an option to use const). > moving the functions to namespaces would be also a bit weird for me, as w= e > currently don't support function (and const) autoloading, so it would be = a > mixed message about whether or not do we consider functions and constants > first-class citizens used together with the later introduced oop features= . > > -- > Ferenc Kov=C3=A1cs > @Tyr43l - http://tyrael.hu > [1] http://php.net/manual/en/language.namespaces.rationale.php --001a113a9556c4d22204ff3d020d--