Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106552 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98938 invoked from network); 12 Aug 2019 10:59:36 -0000 Received: from unknown (HELO poczta.brzuchalski.com) (188.165.245.118) by pb1.pair.com with SMTP; 12 Aug 2019 10:59:36 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 29134298423A for ; Mon, 12 Aug 2019 10:27:42 +0200 (CEST) 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 M_fz6UrfPpCs for ; Mon, 12 Aug 2019 10:27:37 +0200 (CEST) Received: from mail-ot1-f46.google.com (unknown [209.85.210.46]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 0F9B42984233 for ; Mon, 12 Aug 2019 10:27:37 +0200 (CEST) Received: by mail-ot1-f46.google.com with SMTP id e12so11638254otp.10 for ; Mon, 12 Aug 2019 01:27:36 -0700 (PDT) X-Gm-Message-State: APjAAAU5J/MR4sZeV0bVvsXfWbsJCEmLc8r9565B8Pdomyc43wxARujY wiUF+/1jjHT6eZlG5155aVDAZi/5JOE2vDvWMpQ= X-Google-Smtp-Source: APXvYqybBTnXdPnnhqwYGSpzu7um5RArt1QnmrztuVZvQCuvDuynWr5VEsns4eFZKJM684jmAu3OMLDXviXSGsCGk0o= X-Received: by 2002:a9d:7a4e:: with SMTP id z14mr21030918otm.258.1565598455869; Mon, 12 Aug 2019 01:27:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 12 Aug 2019 10:27:23 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Nicolas Grekas Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="000000000000d2b62a058fe74b24" Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --000000000000d2b62a058fe74b24 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nicolas, pon., 12 sie 2019 o 10:17 Nicolas Grekas napisa=C5=82(a): > Le lun. 11 d=C3=A9c. 2017 =C3=A0 14:44, Nikita Popov a =C3=A9crit > : > > > Some time ago I introduced the following proposal for namespace-scoped > > declares: > > > > https://wiki.php.net/rfc/namespace_scoped_declares > > > > The idea is to allow specifying declare directives for a whole library = or > > project using: > > > > namespace_declare('Vendor\Lib', ['strict_types' =3D> 1]); > > > > I've finally gotten around to implementing this proposal ( > > https://github.com/php/php-src/pull/2972) and would like to move forwar= d > > with it. > > > > The reason why I'm picking it up again is some feedback I received for > the > > explicit call-time send-by-ref proposal. The main objection seems to be > > that the feature has limited usefulness if it's optional rather than > > required, because you still can't be sure that something is a by-value > > pass, just because no & is present. At the same time, we can't make thi= s > > required anytime soon due to the large BC impact. > > > > Namespace-scoped declares are perfectly suited to resolve this problem. > We > > can introduce a require_explicit_send_by_ref declare directive to make > the > > call-site annotation required, and libraries/projects can easily opt-in > to > > it using namespace_declare(). There would be no BC impact, while at the > > same time projects could benefit from the additional clarity and > > performance improvements immediately. > > > > I've read discussions about the notion of a "package" and the way we shou= ld > define its boundaries. > What about the following? > > Individual files could declare their package using this style: > > That would be enough to group a set of files together and make them share > eg some private classes, some optional PHP behaviors, etc. > > Why suggesting use of declare for that? Wouldn't a new "package" keyword be more appropriate for that? For eg.: The right side "MyVendor\MyPackage" would also be a FQCN that PHP would > autoload as a regular class. The corresponding class would then be the > place where ppl would declare the engine behavior they want for their > package (strict types, etc). To enforce this, the engine could require th= at > the "MyPackage" class implements some interface/extend some base abstract > class. > > Of course, one could hijack a package and declare an unrelated file as pa= rt > of it, but I don't think that's an issue: the situation is the same as fo= r > namespaces, where one can hijack a third party vendor namespace. In > practice, it proved not being an issue, and the original author's intent = is > clear: "this is my namespace/package, if you mess with it, fine, but you'= re > on your own". > > Nicolas > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --000000000000d2b62a058fe74b24--