Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119461 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39802 invoked from network); 3 Feb 2023 18:30:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Feb 2023 18:30:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 289A41804D4 for ; Fri, 3 Feb 2023 10:30:03 -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-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 10:30:02 -0800 (PST) Received: by mail-lf1-f50.google.com with SMTP id y25so8987236lfa.9 for ; Fri, 03 Feb 2023 10:30:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VBqiycfcbjmSODoS2VLFBeON81wZaFEWoMVQqTQhZG8=; b=VxHcfSQlqCXYFRI/2mwalZg8rPZYdrKHHNKDGufphEWwidKyzm4wjZT9o3i+5BVj/V bBU8tyZdr+f3iVTwf+DMkZbeSBNUu+6bILfK/KSJfaj3No3Q1KRTV4kGDmIVldM7FkXT zUs/AEGsDpZCdFn/Y6NMth7gFWkfkdz2o1mYsWEJF5N0+dRwmJ1ivYt2nKDUVDjYcBvo EQNya4Mc4pT5gCr9zRBgrTq2BxZNAM4Fl2vAOo0t8Gmoc8+TzIHlhpufa69OiX+46vK6 AbME0+YqcFa+oHze8x8D27ocDsEbE7P+YQnYlP74Tmpmcy7Q5Zux5JAqTW/LvUpBya4c Swag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=VBqiycfcbjmSODoS2VLFBeON81wZaFEWoMVQqTQhZG8=; b=N17CSH/AjRzB6p5GYq19MMuRQ5jqxdZn3x7gZkqBTFGAqDH+tWcGIT1UGTEISWG6eQ vcpEGXAsyLoIVnSvpMomWFgzu9uMK1rpKt3c5K5Wq3Qc5+9Gi3XMLwfadLUULMRK1C0O dYi/QO5wBFWugwb6PPfdQUWD4XgEhKbGTbJjNKn2VR7Pfikgj62tMxsbYJdjG2PK2x/v uBc9gI3cYUjih306Usj6SH1DB8b0BVk9oMA/VPNLSzmWBa/UBxw3zxM5LL+TYpyEUhib hEhnbdfiwfWqqT/9NKuVbN3W3iRHd+lnJtWJPFCBrz8DHcfoysmkzwrK//0sFYuimAby AOEg== X-Gm-Message-State: AO0yUKXucpuferx6n1TmS/YG7F4C5YyvTy0OO3CxqMUUgZTdcqYHgNfw QPfEfphjzIsz26+moi7pj/FNQBk34reTMx/5FJo= X-Google-Smtp-Source: AK7set8OmWTJG2lqBUaxQ/BTxIFV5gTqyCsDbTmWv/4l2lmCtaFN+8GygXFqAXEKTKX7JMGtBfdfM5FcK7rwMBNEpF8= X-Received: by 2002:a05:6512:3693:b0:4d8:5f47:e4dd with SMTP id d19-20020a056512369300b004d85f47e4ddmr1673540lfs.49.1675449000970; Fri, 03 Feb 2023 10:30:00 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a2e:ab0c:0:0:0:0:0 with HTTP; Fri, 3 Feb 2023 10:30:00 -0800 (PST) In-Reply-To: References: Date: Fri, 3 Feb 2023 19:30:00 +0100 Message-ID: To: =?UTF-8?Q?Fl=C3=A1vio_Heleno?= Cc: someniatko , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Official Preprocessor From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2023-02-03 17:38 GMT+01:00, Fl=C3=A1vio Heleno : > On Fri, Feb 3, 2023 at 6:19 AM Olle H=C3=A4rstedt > wrote: > >> 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 >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: https://www.php.net/unsub.php >> >> > Why not follow the steps of other projects that have been created > independently from the core and, > at some point, gained enough support/traction that were incorporated into > it? You'd have to rewrite Psalm or Phpstan in C if you want it to be part of php-src. Or write a completely new project. Olle