Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101349 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74387 invoked from network); 13 Dec 2017 07:12:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2017 07:12:45 -0000 Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain brzuchalski.com designates 188.165.245.118 as permitted sender) X-PHP-List-Original-Sender: michal@brzuchalski.com X-Host-Fingerprint: 188.165.245.118 ns220893.ip-188-165-245.eu Received: from [188.165.245.118] ([188.165.245.118:50710] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/99-53433-BE2D03A5 for ; Wed, 13 Dec 2017 02:12:43 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 6BCC32984233 for ; Wed, 13 Dec 2017 08:12:39 +0100 (CET) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f2zMiQxg3SQC for ; Wed, 13 Dec 2017 08:12:37 +0100 (CET) Received: from mail-ot0-f181.google.com (unknown [74.125.82.181]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 995B82984236 for ; Wed, 13 Dec 2017 08:12:32 +0100 (CET) Received: by mail-ot0-f181.google.com with SMTP id v21so1191899oth.6 for ; Tue, 12 Dec 2017 23:12:32 -0800 (PST) X-Gm-Message-State: AKGB3mIH7pN5CNwUD76u46c+XfHWrqjHJ5/fArfZ20BytuMT5PHF5UMx qxOI1AMBg8+nPbUg43ahROhkEr+7wWaULcjjWD0= X-Google-Smtp-Source: ACJfBotGAu7NGnvjQhmI1es9+O0SOlsE34Y28gTmZpIMjuWQOcPORJ+9D8tjOnTrW3rKg7U8zGv9yolNQx2jDFGOftg= X-Received: by 10.157.89.230 with SMTP id u38mr1195735otg.270.1513149151586; Tue, 12 Dec 2017 23:12:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.46.70 with HTTP; Tue, 12 Dec 2017 23:12:31 -0800 (PST) In-Reply-To: References: Date: Wed, 13 Dec 2017 08:12:31 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Andreas Hennings Cc: Nikita Popov , Stanislav Malyshev , PHP internals Content-Type: multipart/alternative; boundary="f4030435beb4ac32ca0560337d1f" Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --f4030435beb4ac32ca0560337d1f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2017-12-13 6:04 GMT+01:00 Micha=C5=82 Brzuchalski : > > > 2017-12-13 5:38 GMT+01:00 Micha=C5=82 Brzuchalski : > >> >> >> 2017-12-13 5:24 GMT+01:00 Andreas Hennings : >> >>> On 13 December 2017 at 05:04, Micha=C5=82 Brzuchalski >>> wrote: >>> > >>> > If we're going to introduce someday a namespace file, then IMO it >>> should not >>> > be putted outside namespace folder. >>> > For eg class Acme\Animal\Cat in src/Acme/Animal/Cat.php should have >>> > namespace file in src/Acme/Aniimal/namespace.php >>> > or even more src/Acme/Animal/ns.php >>> > Why? Because users use PSR-4 so then they're src folder looks more >>> like: >>> > src/Cat.php <-- class Acme\Animal\Cat >>> > src/ns.php <-- that should be then a place for namespace declare or >>> even >>> > function and constants. >>> >>> You are right, my previous proposal src/Acme/Animal.namespace.php >>> would not work universally. >>> >>> But your proposal, src/Acme/Animal/ns.php clashes with the class file >>> for class \Acme\Animal\ns. >>> >>> We would need something other than NAME.php. >>> E.g. src/Acme/Animal/ns.inc.php >>> >> > Actually not true. `namespace` keyword is reserved and none class can hav= e > such name. > This means this example couses a syntax error: > > namespace Acme\Animals; > class namespace {} > > That why we can assume we can utilise namespace.php file name. > And also why not trying to include it on autoload call? > For eg. > > new Acme\Animal\Cat(); // tries to load $file =3D "src/Acme/Animal/Cat.ph= p" > > // but prevoiusly tries to load > require_once dirname($file) . DIRECTORY_SEPARATOR . 'namespace.php'; > > It's bad because it';s magic, but the `namespace.php` filename is still > available to use. > > Andreas, we're touching namespaces which is a hard subject, but if I could fly away with my thoughts I'd propose to introduce something called for eg. a package and then divide it's name in class/function/const name with a single colon, for eg. Acme:Animal\Cat which gives additional information about package which then declares something and may be a good start for future scoped declarations. I've prepared a short gist to illustrate that https://gist.github.com/brzuchal/352ffce2717648f0d43f2d5a0c4bfb7b This solution doesn't require usage of Composer, but needs to pass an aotuloader function a type to load. There was a proposal on internal some time ago to pass additional parameter to load function. > >>> But then Composer would still need to make sure that this file is >>> always included before any class files from this directory. >>> On language level we cannot assume that Composer is being used, and >>> that it is being used correctly. >>> >>> So again this would be fragile. >>> >>> > >>> > Such namespace file can be a good place for namespace function and >>> constants >>> > declaration. >>> > Also I think there is no need for another global function named >>> > `namespace_declare` if we had namespace file >>> > then we can utilise declare for that. >>> > Lets imagine such syntax: >>> > >>> > // src/Acme/Animal/ns.php >>> > >> > >>> > namespace Acme\Animal declare(strict_types=3D1,another_option=3D0); >>> > const CAT =3D 1; >>> > function createCat() : Cat {} >>> >>> This means you are changing the meaning of existing declare() to apply >>> to the entire namespace? >>> Or to the entire directory? >>> >>> >> To entire namespace just like: >> >> > >> namespace_declare('Acme\Animal', [ >> 'strict_types' =3D> 1, >> 'dynamic_object_properties' =3D> 0, >> ... >> ]); >> >> namespace Acme\Animal declare( >> strict_types=3D1, >> dynamic_object_properties=3D0 >> ); // <-- this works same as namespace_declare call above >> >> namespace Acme\Machines { >> // here we have strict_types=3D0 turned off >> } >> >> >>> Or maybe the difference here is that there is no semicolon directly >>> after the namespace declaration? >>> >>> I am not convinced by this syntax. >>> But even if we would find a good syntax, the behavioral problems >>> pointed out by Stanislav still apply. >>> >> >> >> >> -- >> regards / pozdrawiam, >> -- >> Micha=C5=82 Brzuchalski >> about.me/brzuchal >> brzuchalski.com >> > > > > -- > regards / pozdrawiam, > -- > Micha=C5=82 Brzuchalski > about.me/brzuchal > brzuchalski.com > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --f4030435beb4ac32ca0560337d1f--