Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119456 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 915 invoked from network); 3 Feb 2023 09:19:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Feb 2023 09:19:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 58B3D1804BD for ; Fri, 3 Feb 2023 01:19:00 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 3 Feb 2023 01:18:56 -0800 (PST) Received: by mail-lj1-f172.google.com with SMTP id d8so4611603ljq.9 for ; Fri, 03 Feb 2023 01:18:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8pzmqhgqznL9W62NaWfsQHMdDp+yDY3E85rCQVSbofU=; b=aC/UHHZAGzBcxZXw0KgNntBS2lZ37GRxv6vWoImuuDADjne6gOxHOJSd7wP4BieqrK osmELUMH2o391nsdUJnYqcW5dteuBmS32Gjlq3eSKkYMuEJVfJIWbL1Dnfjy1hl1/1l7 /GC8YB0/CfgxVYle8MTqQAJtpI4X5qgAG0+DE0miPexIebmJdWznbQAjsCSVzLpsMIXZ LURvtTV4Ejfjph4Mk7q6QL16p1F+HTR5zTgx0pGOarPtKGILvIO9nO0Ua4/qR5ac3lWQ Y9WRsa1+9VOPxB3YBluJ9nCv+gQFIQjbfOeu/yVxQAAjc6oks4ugM1p3HnvfkZCCiBTv II4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8pzmqhgqznL9W62NaWfsQHMdDp+yDY3E85rCQVSbofU=; b=1sGBh7I3T+eVkW+v/8+fl2z1hsW2l5LIUVVRIwb7KKHMeXl4iEvzCcutFX2O9M0Dtk /ZoGbt3Z6TwwtjBzp61X+v5FJqeziKriKz/BTmSBELwloENthjbhm6mIE5a24++o6AzY 4CBamQytpMVjiSCUcBl8tQpWynVoR8wC4lAUjG+U3VKqyt7lpS7aIPr/lr6jExmIsAmU t5bVryendvYeYTbjOyDgePsHf7ruKrgJYYJ8ACBsbzwz7o4bgssae1YlTabFPrhuXJtP LHIliWIAH/pEgCJerbJZmTKvXMxaXH26oUr9h5S4MggXeRYPS8i9+3Ox+GzRk9M3mpHw X+Vg== X-Gm-Message-State: AO0yUKXKOKlczeMejFOYKTkkeSr0ZbmJHFf9VG7NorUI3RL786ch+gyQ CodBXej9qFVQQHt0LXQRTS9M24eKMBalcnxJZTo= X-Google-Smtp-Source: AK7set+ER/+Ee0jSMzTyTDmksbl2dcSJyEMNij5COg2vul1YCMW9R6fql1EYHaOUH6lauRKja5iatSCfNXHtA2F5Rv0= X-Received: by 2002:a2e:958b:0:b0:290:67a6:38d2 with SMTP id w11-20020a2e958b000000b0029067a638d2mr1445978ljh.184.1675415935259; Fri, 03 Feb 2023 01:18:55 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a2e:ab0c:0:0:0:0:0 with HTTP; Fri, 3 Feb 2023 01:18:54 -0800 (PST) In-Reply-To: References: Date: Fri, 3 Feb 2023 10:18:54 +0100 Message-ID: To: someniatko Cc: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Official Preprocessor From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2023-02-02 15:19 GMT+01:00, someniatko : > Hi Internals > > The main gist: > -------------- > > I suggest to introduce an official type-checker / static analyser / > preprocessor / transpiler for PHP, somewhat similar to TypeScript in > the JavaScript world, which will allow to introduce the features > otherwise impossible for the PHP world, at the cost of including an > additional transpilation step. > > The reasoning: > -------------- > > You all know there are a lot of problems with the language, especially > large gaps with the current type system, which have large community > demand to overcome, but still cannot be solved due to the paradigm > chosen by PHP. And the paradigm is to be statically typed (to some > extent), but dynamically checked language, which limits the number of > available options due to performance reasons. > > The introduction of static types have gradually eliminated the need of > using external means of communicating the types (phpdoc @param and > @return annotations), replacing them with native language constructs, > making the language more expressive and enterprise-ready. However, > there are a lot of things still missing, like types of arrays, > including lists, hash-maps and structure-like arrays, and of course > generic classes and functions. These are still covered nowadays with > external means like phpdoc annotations and static analysers / type > checkers to validate them. This leaves PHP in the odd mixture of > native types and externally validated annotations via comments. > > Paradigm of a dynamically checked language also leaves out the problem > of type-checking before running the code. Even though the types are > defined statically, you still have to physically run the code, with > all possible execution paths, to catch a type error. To avoid that you > still would have to use an external typechecker / static analyser, > even if PHP could cover 100% of type demand natively. > > Python solves this problem nicely I think. It is dynamically typed, > but it allows a special syntax for static types and also has a > separate static type checker. I think this is really a good approach > and it would be great if PHP followed this path for the beginning, but > we have what we have already. > > There were attempts to create preprocessors for PHP (like PHP++ IIRC), > which allowed features like generics, but they did not gain enough > popularity, weren't baked by large enough companies, didn't make their > way to major IDEs support. I believe the only solution is to make an > official one. > > Therefore, I suggest the following thing: > 1. Introduce a new #declare directive which will mark the file as > requiring pre-processing. > 2. Let PHP introduce special features that only work in such > "pre-processing required" files, such as typed lists and generics. > 3. Implement a static type-checker in PHP that will verify those typed > lists and generics are indeed used in a valid way. No need to waste resources implementing a new one when we already have two very competent already: Psalm and Phpstan? Or why is those not enough for your use-case? "The greatest enemy to a perfect solution is a good enough solution already in place." ;) Olle