Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106569 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14251 invoked from network); 13 Aug 2019 20:21:24 -0000 Received: from unknown (HELO mail1.25mail.st) (206.123.115.54) by pb1.pair.com with SMTP; 13 Aug 2019 20:21:24 -0000 Received: from [10.0.1.62] (unknown [49.48.240.10]) by mail1.25mail.st (Postfix) with ESMTPSA id F319560432; Tue, 13 Aug 2019 17:49:44 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) X-Mailer: iPhone Mail (16G77) In-Reply-To: <3db68c5e-54d1-812f-bbf5-1b089cba1bff@gmail.com> Date: Wed, 14 Aug 2019 00:49:41 +0700 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <722174DE-F28F-41A3-BFF2-23E3CA8B44AA@koalephant.com> References: <25d774e8-183b-d39c-4ac4-81c1b7770229@gmail.com> <5d5298a5.1c69fb81.b4ed1.2d97SMTPIN_ADDED_MISSING@mx.google.com> <3db68c5e-54d1-812f-bbf5-1b089cba1bff@gmail.com> To: Rowan Collins Subject: Re: [PHP-DEV] [RFC] Namespace-scoped declares, again From: php-lists@koalephant.com (Stephen Reay) > On 14 Aug 2019, at 00:05, Rowan Collins wrote: >=20 >> On 13/08/2019 12:01, Mark Randall wrote: >>> On 13/08/2019 10:02, Rowan Collins wrote: >>> I really like this approach. It allows a package definition file to exis= t, without either the language or the header of each file having to define i= ts location. >>=20 >> # >> # File: /lib/company/project1/a/b/MyClass.php >> # >>=20 >> >=20 >> declare_import(company[:label]); >>=20 >> namespace company/project1/a/b; >>=20 >> ... >>=20 >>=20 >> # >> # File: /lib/company/__nsmeta.php >> # >>=20 >> >=20 >> namespace company; >>=20 >> namespace_declare [:label] { >> strict_types=3D1; >> strict_operators=3D1; >> upgrade_errors_to_exceptions=3DE_ALL; >> } >>=20 >> final class __nsmeta { >> /* does nothing except be findable by the autoloader */ >> /* and defaults to private constructor so it can't be used */ >> } >=20 >=20 > This seems to be more complicated than Nicolas's version, and involve much= more special magic, like the name __nsmeta, and the class that does nothing= . I'm also not clear on how you're picturing the relationship between namesp= aces and packages. >=20 > The way I understood the suggestion, you'd end up with something more like= this, which feels much simpler and cleaner: >=20 > # > # File: /lib/company/project1/a/b/MyClass.php > # >=20 > =20 > declare(package=3Dcompany/project1); > // or with a new keyword > package company/project1; >=20 > namespace company/project1/a/b; >=20 > ... >=20 >=20 > # > # File: /lib/company/project1.php > # >=20 > =20 > namespace company; >=20 > class project1 extends \PHP\Package { > public function getParserDirectives() { > return [ > 'strict_types' =3D> 1, > 'strict_operators' =3D> 1, > 'upgrade_errors_to_exceptions' =3D> E_ALL > ]; > } > } >=20 > Regards, >=20 > --=20 > Rowan Collins > [IMSoP] >=20 >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 I think this approach is easier to follow (less magic) but has a (small) pot= ential for conflict with existing code that may then require renaming or mor= e (eg if a class existed with that proposed name, and is either a singleton a= nd/or already extends another class). Is it feasible to instead require the class implements an interface that def= ines a static method?=20 Building on that, could the concept of =E2=80=9Cdo something to initialise t= his package=E2=80=9D be made more generic: when a file declares it=E2=80=99s= a member of a given package, the static method on the class that matches th= e package name is called, and it=E2=80=99s up to the developer what it does i= n that method. That would of course also then require a new function to set t= he declares with package scope to be useful for this particular problem, bu= t it also allows more control and power for the concept of packages in gener= al. Cheers Stephen=20=