Re: Migrating PHP classes to built in namespace

From: Date: Thu, 04 Jun 2015 09:04:39 +0000
Subject: Re: Migrating PHP classes to built in namespace
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-86487@lists.php.net to get a copy of this message
On 06/04/2015 10:01 AM, Yasuo Ohgaki wrote:
Hi all, On Thu, Jun 4, 2015 at 12:07 AM, Sara Golemon <pollita@php.net> wrote:
On Wed, Jun 3, 2015 at 1:33 AM, Dominic Grostate <codekestrel@googlemail.com> wrote:
Has there been any discussion or consideration towards migrating or at least aliasing all built in classes to a Php vendor namespace?
Not any that's led to a consensus. Personally, I like the idea of moving EVERYTHING to PHP\ at once and building in an automatic fallback, so an app could do: <?php $dt = new DateTime(...); // uses builtin DataTime via fallback to PHP namespace Or: <?php class DateTime { ... } $mydt = new DateTime(...); // Uses user supplied DateTime $pdt = new PHP\DateTime(...); // Uses builtin DateTime
It's acceptable option, but I prefer explicit declaration for clean root namespace.
Possibly paired with the ability to import a NS to root: <?php use PHP as \; $pdt = new DateTime(...); // Uses builtin DateTime from root namespace
+1 for "as \" It achieves both clean namespace and compatibility at the same time. It opens door for easier API version up also. Automatic fallback disturbs this. This one is not compatible with current code as you have to alias the PHP namespace to the root one before using full classes like \DateTime.
PS: I like a lower case "php" much more than upper case "PHP" ;)
Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net


« previous php.internals (#86487) next »