Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105661 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88820 invoked from network); 10 May 2019 15:32:45 -0000 Received: from unknown (HELO mail-lj1-f177.google.com) (209.85.208.177) by pb1.pair.com with SMTP; 10 May 2019 15:32:45 -0000 Received: by mail-lj1-f177.google.com with SMTP id m20so4966705lji.2 for ; Fri, 10 May 2019 05:37:23 -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=43VfWChU8dhmN41LZvUOWoH7MR9c2BZG3K7DjUMiC4U=; b=OcSMr5F7L3ZTJWz7jyBh2jrSt5so+a3hmwzXbNfJGN3h/w+ZvQs83sXIh2Tlv309r/ C6vHakvkqI9+NQUCgPe/ofOREkIsSKWc5Pk7Ml6W5xvbnVHWsxsYTMtLq0F/1p4T7CfE fnXYyFP2FMHuIiXEOXrw5ZF6FeQS/qZ99CbZEBKgwIHu59Itl6BTbAwsoBYKYJGLHWhX 9T6os5NTJGLcyjcgypXpSmP0evyiuwgyWjaCb2rHytK383wEHn1vQL4OXPc1I4d5VSi2 lFJnE4Qu09eeh0JUmtRTgG1keluaFqOz9WiyXR4c2GIH246l5oDOoeFFiPH5Z6Du8MSZ A0Xw== 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=43VfWChU8dhmN41LZvUOWoH7MR9c2BZG3K7DjUMiC4U=; b=XrpjKa9f19BBhl84gx2lH3aPiInOTD85YayHiEnk9lu0TOxpIsk7WHtyYuK3A3b68R 3PkYBZ/DNSjbQwgqfrzUhnGKA3DrEAR7MmMbpoXGlW9Q2SBpCt2C/WhvfurLKpHgyOx6 wkHud62iumaZNymTRLFdxAwGmGwF8PaqfPzqpwi+OLZ2xRsaOJjcvAt5mcdrEuUcJbOt zu9qdw9vEIYktls9nEuRmuCyvTSfAyZu1iiWq7qWzE04VLMoIzyCpUaNuNt3YCkDzLjk +jgTiGO6Etv/VQ4ByH/k1ywxkunbgxunQ9CRXPIIxnfPTPPMVCofOm4fCEvvTAMoCsHB zroA== X-Gm-Message-State: APjAAAXheWzITLfLnfLhBB+jofzLmDZDsxq1GXZlj67DTOS09pB6g0ij KZgXr4LRvx69uVp1+dYGeOujoukpMkmaqHU2Zck= X-Google-Smtp-Source: APXvYqxTncGzxNNkVi09NSmhXadH5BgagPB+Nz4z2AKqCuXvqpMhS59LqsZdr8/fGqOmfqmiOeAnokggjQzGSVtjxzQ= X-Received: by 2002:a2e:6e0b:: with SMTP id j11mr5771172ljc.46.1557491842741; Fri, 10 May 2019 05:37:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 10 May 2019 14:37:04 +0200 Message-ID: To: Lynn Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000006faed058887d4e3" Subject: Re: [PHP-DEV] PHP header files, restrict to declaring code only From: nikita.ppv@gmail.com (Nikita Popov) --00000000000006faed058887d4e3 Content-Type: text/plain; charset="UTF-8" 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 --00000000000006faed058887d4e3--