Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106551 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97226 invoked from network); 12 Aug 2019 10:58:48 -0000 Received: from unknown (HELO mail-lj1-f174.google.com) (209.85.208.174) by pb1.pair.com with SMTP; 12 Aug 2019 10:58:48 -0000 Received: by mail-lj1-f174.google.com with SMTP id r9so97523952ljg.5 for ; Mon, 12 Aug 2019 01:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MxmoaFaa6LWzfSI9PK96oU1UVMLiD1/cb1q+BWvQ/Oo=; b=ff4rqgmf6BqtdvA82ZKAw8fTOpfNJavC1JJSJFfrwSz19DWtfwSBz56Lkos1DJIZ0i 0AE8c63MEAa0CETFjC117p4lxc/y8mNl7Q4mHjZDjKs4Twci39LYqs4oYFtZi0F6eB+K TdsK1F9I6clFXLlErzuuGkAltlDoHg29mjnjMnyvRjfvPPLxOpT91DFYrrX7qdHM5fiC JoCFgf1Z8ObQbcVWzMa0mB+JpoDNdi0+/0vobbd+yWFo2Te4z44FdO+dVBLRo5OhzY3E yQSbd4AmwTz2FaBNMdys1XETY15lZbU6MB/hkNoGhrtN7/x8oefyIIKdrPS3sZP58AUJ 9aXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MxmoaFaa6LWzfSI9PK96oU1UVMLiD1/cb1q+BWvQ/Oo=; b=ju4RzKp1ql/BTyxpzbIidZpKUirDfgwcMaAxWlhPkNZ3Onw/UaolPEw7FC6RVBcXox xw8EF8XQQh3W9O63Nyu7ZAvyLCYWKuPRQBtWLiO79HNkc+PPGNlTSOcjtorBALJDBC/F qvi1sOpo67P9QhUG5GK2iXm4vPajOSHf7CDJc3FcD6P4W9kw1GV/YeH6giOcZYgbgLIN 9GgTwEaZbTUP4MkFeJOiyrq+NU7OlcF1BSiCDO7N0ol6NK9DcqaNQGCf+pgDndYx4tlC s6bWwekBOU+psNQcT4NC6kH1Gvt4FVOH5z3wmaUnalZvMjPNvFHnPIR+63QYm+e0R6dY qDhw== X-Gm-Message-State: APjAAAUxJvmhRuXXCyYHUmwJ4exgvakHg75t2H9+LQBIxva2SqR6srZQ JNPWscgPA8c3wbMlrQv+i7O81IPrkE+NwcmPrXU= X-Google-Smtp-Source: APXvYqxCn5xlui1zyWtdRv6MODJ4v6a+Njv1YWyA77TAc8PRER4RbHkaUWjmhHThRUKZqXM8Z1EbunXOmuCIhLetaOs= X-Received: by 2002:a2e:81c3:: with SMTP id s3mr8820567ljg.70.1565598413994; Mon, 12 Aug 2019 01:26:53 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 12 Aug 2019 10:26:37 +0200 Message-ID: To: Nicolas Grekas Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000053bdb4058fe7491c" Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: nikita.ppv@gmail.com (Nikita Popov) --00000000000053bdb4058fe7491c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Aug 12, 2019 at 10:17 AM Nicolas Grekas < nicolas.grekas+php@gmail.com> wrote: > 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 o= r >> 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 forward >> with it. >> >> The reason why I'm picking it up again is some feedback I received for t= he >> 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 this >> 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 t= he >> 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 > should 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. > > 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 > part of it, but I don't think that's an issue: the situation is the same = as > for 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 > FTR I've created a draft-implementation for a package system here: https://github.com/php/php-src/pull/4490 It uses a slightly different approach in that it keeps the package name a string (that should usually match the Composer package name) and uses a function to register the package. The main annoyance is that this requires declaring the package in every file, something I would like to avoid. An alternative I played with is to allow specifying the package at include time, which would allow the autoloader to specify which package a file is part. However, while this is more ergonomic for the user, I'm afraid that this will make static analysis & IDE scenarios problematic, because they will not be able to easily know what the package is in cases that fall outside convention. So in the end, an explicit per-file package declaration may be the best we can do. Nikita --00000000000053bdb4058fe7491c--