Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101342 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51425 invoked from network); 13 Dec 2017 00:16:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2017 00:16:39 -0000 Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.215.52 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.215.52 mail-lf0-f52.google.com Received: from [209.85.215.52] ([209.85.215.52:39138] helo=mail-lf0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FA/C6-53433-661703A5 for ; Tue, 12 Dec 2017 19:16:38 -0500 Received: by mail-lf0-f52.google.com with SMTP id l81so687549lfl.6 for ; Tue, 12 Dec 2017 16:16:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KG4zCjGheU9Y0z78W+VqS8NpNOMIR8kBPwmcjfMdG04=; b=DAWv64lxkksflOIet6VtkEq5+n4xI02NnMVEP9OlkyU7TEbrU5pRPluHH6cck7u2aK Ptp5IWQdVgVgPBnV99r1ZF5P0f0rl8Meu22TLqOsYYgabekkOdisB9EgR4mrbpWLXWGy BlwufY5qZ9YQis7YUEtWba9g0JK6ptdXawtixxj1k2TcOvUFAHaIdklVWrmNBR/CxKxN fLZR/lNapbnHJ1gZRtFV+J26y1S/hnaEdgZdEQ/gERB+SX1yIzqnpDUPagQxUG5ZQzNr zaDIQ9IKnbuUTbDUUKjuL35/tGOg+4TY4bTLJLaOFcBAwp4EyKfOZbjfsWFy1BYq2rxX QM1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KG4zCjGheU9Y0z78W+VqS8NpNOMIR8kBPwmcjfMdG04=; b=XhAeAa8wRQ332cQ7xsQhPhTGMquRDcLcinqrAx5/S79uIuCj6yiNVexT7jTjQymYJE eoI0EPBC3oOvV90Xv35njs6SgBApkPLvW7eqpNFbgYnrsiUh6hbRKdOpfuQ4jRIALtvO oqUg73J1ECZ/DtiKZEXlFQJY4gSrkfe6G8VGPPnXTaNZjDL1bKU3vk7Lq6ColLyLsA1W tZB/3SaRwRyolHIoTnMvhkrN4ddwiv97B2QG2yzo4AaCFclzj+tSUEcudguI34NsGiMD SMIi+QEhxxXzPBssRJ5B1Qe7w64YT7hS7iO6BRpt00g1WSF2q2Ob9mltTMJYxErL5xmr jR2A== X-Gm-Message-State: AKGB3mK9PwFwKXVGXBPcFPuzwcAtW2WrI0i+PVTJVTrcWNySrDLIadqA UMqp9z/3vnITY39D1TJMBngvhXJJ X-Google-Smtp-Source: ACJfBotcyhXO0Jfq/GkqFYV2A5k2P/Dn19b+xNSaDQfcupOdOY2SmdBBlZbxJqwgVRhYC5nqlqrDpA== X-Received: by 10.46.4.146 with SMTP id a18mr330745ljf.37.1513124195164; Tue, 12 Dec 2017 16:16:35 -0800 (PST) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com. [209.85.215.52]) by smtp.googlemail.com with ESMTPSA id h26sm66672lfb.27.2017.12.12.16.16.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 16:16:34 -0800 (PST) Received: by mail-lf0-f52.google.com with SMTP id 74so706396lfs.0 for ; Tue, 12 Dec 2017 16:16:33 -0800 (PST) X-Received: by 10.25.41.194 with SMTP id p185mr340556lfp.125.1513124193406; Tue, 12 Dec 2017 16:16:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.170.16 with HTTP; Tue, 12 Dec 2017 16:16:12 -0800 (PST) In-Reply-To: References: Date: Wed, 13 Dec 2017 01:16:12 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Nikita Popov Cc: Stanislav Malyshev , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: andreas@dqxtech.net (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' => 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 they >> 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 library >> 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 dependence 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. > 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, and 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=8.1);" to combine all the declares that would be considered default in PHP 8.1. Or introduce some other shortcut like "