Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76220 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39501 invoked from network); 28 Jul 2014 08:22:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jul 2014 08:22:36 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.45 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.216.45 mail-qa0-f45.google.com Received: from [209.85.216.45] ([209.85.216.45:44742] helo=mail-qa0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/93-26001-B4806D35 for ; Mon, 28 Jul 2014 04:22:35 -0400 Received: by mail-qa0-f45.google.com with SMTP id cm18so7402453qab.32 for ; Mon, 28 Jul 2014 01:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=zs3rRRmU6MQ3AZkG9CQJ3KpICUu1Oe3xKhlrJmvQoUg=; b=q1d0MeZmygRulEu8l95VAzTDrhxFtpmsJ2ef6HPAs2RQF4ByY3LiL9DImnfFUL83rM GT0MoZD9EOer4/NckEnN7qgbdmpRS4UW/Aj2rTYxscma3oJq7QpXyAPak6F1+hKll2qg ABaG1XX3tlzTHG4cKCbwpFUsTpP+gnIsKiqNcgGTnm2jAUZqJk4ornl3IAbbE2gSs514 rrOgvdVaQjIfU+x8sgkvf0ZDgn/xc8l1gFsnIJ4/+xkbSyVawxWM0J0DOfwkdNbTuZPD 59AQn0Wcmgda8VLgdX1/qnNUSkAKE5+KN56fjGUUZlC+naFMTeSZpCbxC9o6wA4PhkSE 1Agg== MIME-Version: 1.0 X-Received: by 10.224.4.73 with SMTP id 9mr57353909qaq.12.1406535764213; Mon, 28 Jul 2014 01:22:44 -0700 (PDT) Received: by 10.140.102.111 with HTTP; Mon, 28 Jul 2014 01:22:44 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Jul 2014 10:22:44 +0200 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c21eda97057a04ff3ca052 Subject: Re: [PHP-DEV] "PHP" namespace? From: tyra3l@gmail.com (Ferenc Kovacs) --001a11c21eda97057a04ff3ca052 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 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 > hi, I think it would make sense to announce that the php namespace is reserved for internal use, but I don't think that we are ready for moving everything under namespaces. 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/class, 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 we 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. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --001a11c21eda97057a04ff3ca052--