Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101343 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59486 invoked from network); 13 Dec 2017 04:04:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2017 04:04:47 -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:33387] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C0/67-53433-3D6A03A5 for ; Tue, 12 Dec 2017 23:04:36 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 59D992984239 for ; Wed, 13 Dec 2017 05:04:32 +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 WLv5fj9JheIf for ; Wed, 13 Dec 2017 05:04:25 +0100 (CET) Received: from mail-ot0-f177.google.com (unknown [74.125.82.177]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 1DC5A2984233 for ; Wed, 13 Dec 2017 05:04:25 +0100 (CET) Received: by mail-ot0-f177.google.com with SMTP id q3so928260oth.2 for ; Tue, 12 Dec 2017 20:04:25 -0800 (PST) X-Gm-Message-State: AKGB3mL5ZP4t8mNF/gu3LT1JW44s/rO72t8hvg/nz8TS36AXyCgQbRXd F0aSEbnDRBoEhueUTNK9lMJWTg4gYzyL5KlCq1o= X-Google-Smtp-Source: ACJfBovtkpt5WnEo7G8/McLYtdxru5lm9VRmARP60ApL0J/acIjtiZbd/2GhU++r9BVBITJJ8d2a8KCqUBqPnpvb3Bs= X-Received: by 10.157.89.173 with SMTP id u45mr1013785oth.341.1513137863999; Tue, 12 Dec 2017 20:04:23 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.46.70 with HTTP; Tue, 12 Dec 2017 20:04:23 -0800 (PST) In-Reply-To: References: Date: Wed, 13 Dec 2017 05:04:23 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Andreas Hennings Cc: Nikita Popov , Stanislav Malyshev , PHP internals Content-Type: multipart/alternative; boundary="94eb2c1e9930e1495d056030dcae" Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --94eb2c1e9930e1495d056030dcae Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2017-12-13 1:16 GMT+01:00 Andreas Hennings : > I agree with all of Stanislav's emails in this thread so far. > > On 12 December 2017 at 14:43, Nikita Popov wrote: > > On Tue, Dec 12, 2017 at 8:46 AM, Stanislav Malyshev > > > wrote: > > > >> Hi! > >> > >> > The idea is to allow specifying declare directives for a whole > library or > >> > project using: > >> > > >> > namespace_declare('Vendor\Lib', ['strict_types' =3D> 1]); > >> > >> I am not sure I like this. Namespace is a prefix to a class name. > >> Anybody can declare a class with any name, and the side-effect that th= ey > >> would inherit some context, which is completely invisible and would > >> magically exist somewhere globally, does not seem like a good idea to > >> me. Moreover, what if something - like older version of the same libra= ry > >> or test or something like that - would have different idea about what > >> that global state should be? How nice would it be if a piece of > >> unrelated code could completely change how my code is interpreted? How > >> nice would it be if whether it works or not would depend on in which > >> order classes were loaded in this particular request? > >> > > > > The way PHP works, it's not possible to have two versions of a library > > loaded at the same time. > > Really? > PHP does not even know what a "library" is. PHP sees files, > directories and namespaces. But it does not know how to conceptualize > any of this as a "library". > > With Composer you get the notion of a "package". > In general, Composer would prevent you from using different versions > of the same package. > But you could manually download two versions of a package, and wire up > the class loader in a way that it would load some classes from one > version, and some classes from another version. > E.g. if a class does not exist in version 2, load the class from > version 1 instead. > > PHP as a language should not assume that someone is using Composer > correctly. > > And even if we avoid two package versions coexisting: There could > easily be two distinct packages that use the same namespace. > We could discuss if this is a good idea, but it should not be the job > of PHP as a language to make this situation difficult. > > > > > There is no dependence on loading order. The implementation is careful = to > > ensure that the used declare state is consistent. It's not possible to > call > > namespace_declare() twice on the same namespace. It's not possible to > first > > load some files from a namespace, do the namespace_declare() call and > then > > load some more files. If a namespace_declare() call succeeds without > > throwing an error, then that is the ground truth, without any dependenc= e > on > > order or other calls. > > So by "is not possible", in fact you mean "will trigger an error". > > I imagine with Composer we would have to agree on a canonical file > name where a namespace_declare() would be found. > Maybe something like in src/Acme/Animal.namespace.php. > > The class loader would then have to make sure that this file is > included before the first class from that namespace is included. > Or alternatively, Composer init script would have to include all such > files at the beginning of the process. > > If Composer (or whichever tool one wants to use) would include class > file src/Acme/Animal/Cat.php without prior inclusion of the > Animal.namespace.php, the class file would be interpreted without the > desired setting. > If the process then continues without ever including > Animal.namespace.php, it will silently misbehave. > If, however, Animal.namespace.php is included some time later in the > process, then it would notice that something went wrong, and trigger > an error. > > 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. 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 I haven't thought too carefully about whether having an option for the > > explicit-send-by-ref feature *specifically* would be beneficial, but I > > think it's very important to at least have the option on the table. Too > > many issues in PHP cannot be solved for reasons of > backwards-compatibility. > > We need to have *some* way to evolve the language without BC breaks, an= d > I > > think namespace-declares are an elegant way to do this. > > > So if you want a setting for explicit-send-by-ref, why not do this per > file, as we already do for strict_types? > > If at some day in the future we find that the declares become too > verbose, we could bundle multiple declares into a new setting. > E.g. something like "declare(php=3D8.1);" to combine all the declares > that would be considered default in PHP 8.1. > > Or introduce some other shortcut like " opening tag. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --94eb2c1e9930e1495d056030dcae--