Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106861 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10363 invoked from network); 5 Sep 2019 00:42:18 -0000 Received: from unknown (HELO mail-qk1-f172.google.com) (209.85.222.172) by pb1.pair.com with SMTP; 5 Sep 2019 00:42:18 -0000 Received: by mail-qk1-f172.google.com with SMTP id m2so179907qkd.10 for ; Wed, 04 Sep 2019 15:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=HVtmg5yLsB6nVbUUkL1qCZEGTjZO7QkskxFW9Bs1BUw=; b=rB7W75Bjj80lVUi7xI/WUh9lAvq+jrdP0KaLAKW3aB+CN7MpxaCf4iilMOGuF3viuZ PxyJaaFfFTml3gdoZOxiSd/kJBlmZ1653yEiCbFx6UIWJBiYa9hPv6xsE8Ocw3Yv6nDp VVymbKDHHUClaGdYwVzzcUFyBSJYsEmrUeBq9p0WmgoEkcQ/8LsqiJkEUd7CObFY50h9 iBdJyCM+KR/KglxbvgAqHfwXlhgOXegjSY+cq15NKS+A24SldpyxDBqnw+N1Ujfo2l2O bqxTfBg4J9HEjF9zee5fKDYHZ1trZ5FUQOU1ALCHPdaKpxwxt8pwMYAqzPCn4j8RyOCA OX5g== 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:content-transfer-encoding; bh=HVtmg5yLsB6nVbUUkL1qCZEGTjZO7QkskxFW9Bs1BUw=; b=Pp2+D11YtR6p6+5DoAf0o+00223a4d8pqAukn4OLTu8JV7FBWy/53Ga1L0t140KoPZ lsoWj+K/cp3C9jKBY/qNs4mMkJu8amYvrcNfXLn8hnPfxUflI5CsIn5Dv7SVt04f1Fwt IvSWM3D0Y9nlvvYKVV0fHt7xviWD1QwFxxvBr96lRDHK9Uwj8UCCCKB5/9qtBJwJcjOh Ft4csmLYB9KSTWOu9kY892TX8E81PYytCop8y0xysiNIVWd7TCjcd/1njDhfFQ4tXD8o hccwXHSngcwXngN6KEd2gknoBdDv3N+RNsKLZXTvS/MhW9CcuvzdldLSJKJ7/BA+KVP+ 3yvA== X-Gm-Message-State: APjAAAVAqnMMfd1PH7sOyuNDjnSeI3hAdcr+Idb7TH8MrNpVWbRodQVq SboR5TrilX2IitiabUEsBsu3lQg3ovs= X-Google-Smtp-Source: APXvYqyvGfFLikQMaOHiRARbosv3ddI8Y1ySUrlejm7Wnjf/d3aVRM4OAIzVOVk+BC0TPylWMYL6AQ== X-Received: by 2002:a37:b643:: with SMTP id g64mr22100390qkf.463.1567635377974; Wed, 04 Sep 2019 15:16:17 -0700 (PDT) Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com. [209.85.222.169]) by smtp.googlemail.com with ESMTPSA id u28sm161557qkj.52.2019.09.04.15.16.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Sep 2019 15:16:17 -0700 (PDT) Received: by mail-qk1-f169.google.com with SMTP id o11so194305qkg.8 for ; Wed, 04 Sep 2019 15:16:17 -0700 (PDT) X-Received: by 2002:a37:9984:: with SMTP id b126mr6698477qke.46.1567635376731; Wed, 04 Sep 2019 15:16:16 -0700 (PDT) MIME-Version: 1.0 References: <25d774e8-183b-d39c-4ac4-81c1b7770229@gmail.com> <5d5298a5.1c69fb81.b4ed1.2d97SMTPIN_ADDED_MISSING@mx.google.com> <3db68c5e-54d1-812f-bbf5-1b089cba1bff@gmail.com> <5d52f72d.1c69fb81.8f95f.57a1SMTPIN_ADDED_MISSING@mx.google.com> <2bcb05d6-abf6-4fcb-599e-eaf4bcd58878@gmail.com> <182a6bd5-4057-7ba1-2cca-ab0be37e0b75@gmail.com> <72896017-20d0-16af-b188-8500777f947b@gmail.com> <00eea416-23be-6629-2e94-4cfa9f5fcb39@gmail.com> In-Reply-To: Date: Thu, 5 Sep 2019 00:16:05 +0200 X-Gmail-Original-Message-ID: Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: Rowan Collins , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: andreas@dqxtech.net (Andreas Hennings) I would like to make a wild proposal. ## Proposal Similar to spl_autoload_register(), we would provide a function that allows to register a callback to provide the declares / edition / compatibility information for a given file, before this file is loaded. To address performance concerns: - The result of the callback is cached per file, and per "application cache key". (*) - The callback has the option to additionally provide compatibility information for an entire directory, or a path pattern. Callback signature: - The primary parameter is the absolute path of the file, after symlinks are resolved. - Additional parameters could provide the version of the path that was passed to include / require. - An additional parameter could provide the class name, if we are currently doing autoload lookup (ouch, this could be complicated). - An additional parameter could contain the namespace. This would require that the parsing already begins, before the compatibility information is available. - An additional parameter could contain class names and function names declared in the file. This would imply that the file is already parsed before the compatibility information is available. (*) Caching mechanism: - Different PHP "applications" can have different cache keys, so that they do not poison each other. This could be provided in the initial function call along with the callback. - If no cache key is provided, the starting script path is used (e.g. /path/to/index.php) - There needs to be a function to clear this cache for the current applicat= ion. - The opcache could contain different versions of a file for different compatibility levels. Combination with other proposals: There could still be functions to set compatibility information for an entire directory or namespace preemptively. There could also be ways to disable this special file-by-file callback for specific directories or namespaces. ## Motivation We saw proposals where the "edition" or "declares" would be on file level, on namespace level, on directory level, or on package level. The basic idea (mostly) was that the author provides compatibility information which is then picked up by PHP. The author of a package should be responsible for this, and it should be protected from side effects from other packages. Any file or package should have one definitive compatibility info, which should not be changed from outside. The proposal turns this on its head. It is now the responsibility of the package manager (e.g. Composer) or the framework to organize different compatibility levels in the application. Once some conventions have been established by the community (e.g. Composer), the IDE can extract information from e.g. composer.json to apply the appropriate checks on each file. Benefits: - Fine-grained control where needed, e.g. override the directory-level or namespace-level compatibility information for specific files. - Keep boilerplate out of the file header. No need to update all files when a new compatibility type / edition is released. - No verbose and noisy git commits in the package history. - Option for shared compatibility information across "packages", e.g. for the entire application. - No need for an artificial "package" concept on language level. Let community tools (e.g. Composer) define what a package is. - Possibility to test-run an application or specific files with different compatibility level. - Possibility to control compatibility level based on dynamic file lists, which can be updated based on error statistics, or which can be updated file by file to slowly make an existing codebase compliant with a new version. - The average developer only needs to learn the API of the framework or package manager, and does not need to deal with this on language level. Flaws: - No explicit compatibility information when looking at a specific file. ## Assumptions It is a assumed that "compatibility level" does NOT change the meaning of c= ode. When running a file with a different compatibility level than it was designed for, we may get errors and warnings, but we do not want to get silent changes in behavior. Now I want to see this idea being barbecued.. On Wed, 14 Aug 2019 at 12:27, Micha=C5=82 Brzuchalski wrote: > > =C5=9Br., 14 sie 2019 o 12:17 Micha=C5=82 Brzuchalski > napisa=C5=82(a): > > > > > > > =C5=9Br., 14 sie 2019 o 12:11 Rowan Collins > > napisa=C5=82(a): > > > >> On 14/08/2019 11:07, Micha=C5=82 Brzuchalski wrote: > >> > Exactly so how would it know from string name either it should load > >> class > >> > from src/Foo.php or src/__nsmeta.php if there is no information? > >> > >> > >> It wouldn't. It would include src/Foo.php, and that would have the > >> definition of something with the name "Foo" - either a class, an > >> interface, a trait, or a package. If it wasn't what the engine was > >> expecting, it would be an error, just as it is right now if you write > >> "implements ClassName", or "new TraitName();" > >> > > > > Following that would introduce unneeded additional directory hierarchy > > level in a usual library > > which uses PSR-4 which is the most used one, right? > > > > /composer.json > > /src/Foo.php > > /src/Foo/ <- all package classes should go here? > > > > Going even further by the example of Doctrine libraries: > # doctrine/collections - Composer Package [1] > uses PSR-4 autoload with "Doctrine\\Common\\Collections\\" prefix > to adopt package concept it would have to change the prefix to > "Doctrine\\Common\\" > to find Collections.php and all the rest of source code in Collections > directory > > # doctrine/common - Composer Package [2] > uses "Doctrine\\Common\\" prefix should change into "Doctrine\\" to be ab= le > to load > Common.php and the rest of source code in Common directory > > # ocramius/package-versions - Composer Package [3] > uses "PackageVersions\\" prefix and then what? > > [1] https://github.com/doctrine/collections/blob/master/composer.json > [2] https://github.com/doctrine/common/blob/master/composer.json > [3] https://github.com/Ocramius/PackageVersions/blob/master/composer.json > -- > regards / pozdrawiam, > -- > Micha=C5=82 Brzuchalski > about.me/brzuchal > brzuchalski.com