Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106578 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28385 invoked from network); 14 Aug 2019 09:17:12 -0000 Received: from unknown (HELO poczta.brzuchalski.com) (188.165.245.118) by pb1.pair.com with SMTP; 14 Aug 2019 09:17:12 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 2D582298423A for ; Wed, 14 Aug 2019 08:45:47 +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 z3HAFvZg2xWv for ; Wed, 14 Aug 2019 08:45:42 +0200 (CEST) Received: from mail-ot1-f54.google.com (unknown [209.85.210.54]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 772472984233 for ; Wed, 14 Aug 2019 08:45:42 +0200 (CEST) Received: by mail-ot1-f54.google.com with SMTP id c34so39919998otb.7 for ; Tue, 13 Aug 2019 23:45:42 -0700 (PDT) X-Gm-Message-State: APjAAAXO5oV2CUitvSACTIaKEaEzk3tt+gUX8WOoyZ4Xxw3qmmIcZIf6 2n4tEtfe9/YmM1/P3BV5K1jqGZi5+OtiLhmvi64= X-Google-Smtp-Source: APXvYqz/VccFw0bWTiecyI7wLuqw9G2YHpC+OUavzyOhLSmBT14oISiDOE7nTVxfwOHKBWOkt5IWnpDSuVS06niDX4k= X-Received: by 2002:a05:6830:1085:: with SMTP id y5mr7242234oto.214.1565765141197; Tue, 13 Aug 2019 23:45:41 -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> In-Reply-To: <2bcb05d6-abf6-4fcb-599e-eaf4bcd58878@gmail.com> Date: Wed, 14 Aug 2019 08:45:26 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000000af90a05900e1b2c" Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --0000000000000af90a05900e1b2c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Rowan, wt., 13 sie 2019 o 22:26 Rowan Collins napisa=C5= =82(a): > On 13/08/2019 18:45, Mark Randall wrote: > > I thought about this as my first consideration, however it effectively > > requires that the PHP code within the package class is fully parsed > > and executed in order for it to retrieve the data. > > > > Consider pre-loading where the code is compiled, but not run, it would > > not be possible to use namespace level defines to add compile-level > > optimizations or checks (at least without some AST hackery). > > > Ah, that makes sense. Does that necessarily mean we need a dummy class, > though? The autoloading logic in the engine knows that it called the > autoload callback expecting a package definition, so can count as > success that the package is now defined. > > In other words, the file the autoloader included would look like this > (again, sticking to the notion that "package" is separate from > "namespace"): > > > # > # File: /lib/company/project1.php > # > > > packagedef company/project1 { > strict_types=3D1; > strict_operators=3D1; > upgrade_errors_to_exceptions=3DE_ALL; > } > Was thinking a while about proper syntax and would like to mention what I said before. It doesn't have to be a new syntax if we agree to put package definiction in sort of separate configuration file. In the end all what we need is package name and a bunch of declare directives. Given that it could be easily done using separate conf file like: # package.ini [package] name =3D MyVendor\MyLibrary strict_types =3D 1 encoding =3D UTF-8 # package.json { "name": "MyVendor\\MyLibrary", "declare": { "strict_types": 1, "encoding": "UTF-8" } } # package.toml [[package]] name =3D "MyVendor\\MyLibrary" strict_types =3D 1 encoding =3D "UTF-8" # package.yaml name: MyVendor\MyLibrary strict_types: 1 encoding: UTF-8 That way it would prevent to mix normal PHP code with package definition, cause every possible PHP syntax we would agree, opens the door to add something more to that file, for eg.: # package.php