Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105662 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 174 invoked from network); 10 May 2019 16:10:42 -0000 Received: from unknown (HELO mail-it1-f182.google.com) (209.85.166.182) by pb1.pair.com with SMTP; 10 May 2019 16:10:42 -0000 Received: by mail-it1-f182.google.com with SMTP id u186so9099371ith.0 for ; Fri, 10 May 2019 06:15:21 -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=qMIihbSt5vEmlc1jkNDNy36A1PYnDbqo6et4gIug8gw=; b=icf0dYRVBlryl9+hRs9+EWDmvkJci6hq5foGfezXxFUqqL4NOvfh0JjjB6zsujpgEd 7SsoJi+DaurVzOLSsy9IE1zgg7DpPA3ntg25B3CQl9tpzI6P8fum34IP91PJjdoaqhgK RwYoUIwzaDqZ6pGN+KqGRZagszPVgiMtr8g7oMgpc982RXOUFptvDH8qaD7k1pFCDRKK fdU1ezKr/ae7B7jYMuMtLhQi70bCWlKjifFptePf5lgLpFxmhBSCug8o1L9FWj/dp4tp LTzs9OmYKEjAK9zR6uogL6xC9vsNOHXXPuEtotMWzXw+uBtxRopro+38YeyGUsrWck2Q hyRA== 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=qMIihbSt5vEmlc1jkNDNy36A1PYnDbqo6et4gIug8gw=; b=eCIwjmNDsD42kX0OYWYKQqLQUa2vhGn6S/oViCGk32mYpZ8U5sZfdJzR0pcmKyKonI acUr2mwFtJOpu1dPIAien6FK6CDD4WRyZRpTpuExoe8qki4qraXfVeNF9yzqwAc4WY/C iEx3E//1bma5X4LtL5xbXPiIADlZahxwCKjEc6WO0dKp2eG6Mr9e143HBPS7sh1AdOTC c2GqPuQ3FWjlyUsM7zN/5/MsgF3ej7WIW95sF8E52IO7QRsXJBx+nnYzbsNY/CT7F+qy ChwZ3WMrjvRyNQgW6ch0N8rVHK6P20KLkJXvsSdXi7Ji77p0iwpLGS7aeH+fFbai1Isg Ig1g== X-Gm-Message-State: APjAAAVaQspeWd6+q1cVYu2qjBOeGglPW3DOJS0MbEQH0ob2t5KRSBQ5 RZSWpDNzWacVjlEIpoombBEFqqL9vao+cI6rkHE= X-Google-Smtp-Source: APXvYqwb3pAxpSEHA0wyROj03gSOTNlIHLZvC9I97hKw9DpHy1G0NivaHUD+XJwIZRRFuZyhgZ3RxCD6rcqe/Wz7DxM= X-Received: by 2002:a05:660c:111:: with SMTP id w17mr7160011itj.62.1557494121201; Fri, 10 May 2019 06:15:21 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 10 May 2019 15:14:55 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000d584950588885b14" Subject: Re: [PHP-DEV] PHP header files, restrict to declaring code only From: kjarli@gmail.com (Lynn) --000000000000d584950588885b14 Content-Type: text/plain; charset="UTF-8" Hi Nikita, By limiting a header file to declaring code only, a couple of issues could be tackled: 1. No side effects when loading files. You can assume the global state remains the same, no code is executed by this file, and no output can be sent. 2. Certain features, can be restricted to php-header files only, meaning it does not affect "normal" PHP files. This might open up a whole new range of syntax possibilities that are currently blocked, such as `@trigger_error()` vs `@Annotation()`. I can understand if those reasons are not enough to merit a whole new concept as a header file as it might introduce more complexity than it's worth. Regards, Lynn van der Berg On Fri, May 10, 2019 at 2:37 PM Nikita Popov wrote: > On Fri, May 10, 2019 at 2:30 PM Lynn wrote: > >> Hello everyone! >> >> This is my first mail to the internals, my apologies if I made a mistake >> somewhere. >> >> I would like to propose a new type of php "file" called "phph", short for >> "php-header". >> This file could receive an optional open-tag: `> `declare(header=1)`, >> not sure what's more feasible, or if there are better solutions. This open >> tag could be >> optional for forward compatibility towards omitting the tag. >> >> Php-header files would be allowed to only contain declaring code. This >> means that any code >> that would run "while loading", would not be allowed and cause a syntax >> error in the same >> fashion as trying to add a function call in the middle of a class >> declaration. >> >> ```php >> > // forward compatible? change default in a major version? >> // any other ideas? >> declare(header=1); >> >> // syntax errors: >> echo 'foo'; >> $a = 'b'; >> >> // valid >> class Foo {} >> interface Bar {} >> function baz() {} >> // etc >> ``` >> >> By restricting it to declaration only, it would make it possible to add >> extra features to >> classes, such as annotations as there are a lot less edge cases to think >> about: >> >> ```php >> > @trigger_error('Foo is deprecated as of 2.0, use Bar instead', >> E_USER_DEPRECATED); >> class Foo {} >> ``` >> >> New scenario could be: >> ```php >> > declare(header=1); >> >> use Php\Debugging\Annotations\Deprecated; >> >> @Deprecated('Foo is deprecated as of 2.0, use Bar instead'); >> class Foo {} >> ``` >> >> This is a pretty rough sketch, and I'm not exactly sure if this is doable. >> I'm really eager >> to have native support for annotations and perhaps this idea could inspire >> someone with a >> solution to make this feasible. >> >> Regards, >> Lynn van der Berg >> > > Hi Lynn, > > I'm not sure I understood what the benefit of introducing a header file > concept will be. Could you elaborate more on how this will help annotations > (or other functionality)? > > Nikita > --000000000000d584950588885b14--