Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119460 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33231 invoked from network); 3 Feb 2023 16:38:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Feb 2023 16:38:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 76EE8180505 for ; Fri, 3 Feb 2023 08:38:43 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.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 08:38:43 -0800 (PST) Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-1685cf2003aso7225484fac.12 for ; Fri, 03 Feb 2023 08:38:43 -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:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6yXcUE+2Gi+GoKp/RmWpN7vle2h/S/b9fXfqskFcrx8=; b=K0WeL3sU2fT/OCgjkUg7WWJ9g9VH6vgnvSyY64oiH2WTL5GbNLlo2iJhckFP520lvz 1e9Ht1Qj0LfLWZciMn3M7F8GWI7eN7hI/tenTa084jwBHSe2iwSj62ELAiwThTpudwMs 0azvvY+A9QejC8Y+PPiR9YBk6HvzvB1/R5Qunhoad3f3Xpx1Vljm6OgsBLavRTfnFGyu MG8P1V1YUNSi2h1bT/mah6IaRGXmheFU5LcryqjVqfjFpfGsJL6UGjCW0QF2/g2nSWVm piThXACHM3smR8Cg8UBo2mAly/uKczm/iQ1IogKpxP4Wtb+JEsHP88hrzqsgWVoJCECQ VVgw== 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:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6yXcUE+2Gi+GoKp/RmWpN7vle2h/S/b9fXfqskFcrx8=; b=T43A5fDGbr2ZnOfO4zExhnaTquqTsc+7BHhArO0qBKOK+/FEeoe4KbapSGzGzykXbL j+zq/8s9j9oWTV7otvTY/NHuCpKGpqsSsBvvKhf9fL4H+ixpHm+brtOuzDWaOJUXVmK6 Eh5AU8jGIfdilxfhWu2J3A35F5lhb8EExybzyiP3QUk6nRri7VK1OjAQbzHJHCUGKrjN UTtYvNENB9L+8+nah7fvbeC02jXeyGUeivkK3u80UW5JsAAyLpKbGX3H95hSRS4yjX5v HgJ5g03CfWG5hyWqyN6plp9tfKwlZPmLiknHl31tl1USqV9vfYN+4pC3C0I7wkG9SraH /0Fg== X-Gm-Message-State: AO0yUKXrOh8uWe5hFcxoGUxrQhgZUBtDF/9hZnKdzn8d8GcRe3YkUUB0 62p8mSuAWHyIwlzux7aYnolPgQ+I8384aPVRK2Q= X-Google-Smtp-Source: AK7set8rZN3fJYliBjipa6A2u7GNLHPNfd7BtQFmV7PAQq7PYlOHHJ39aN6YHxKhdQKyHAU4RAkiUq8YuMlMdeKZvfU= X-Received: by 2002:a05:6870:5687:b0:163:922d:fb92 with SMTP id p7-20020a056870568700b00163922dfb92mr619519oao.33.1675442322320; Fri, 03 Feb 2023 08:38:42 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 3 Feb 2023 13:38:31 -0300 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: someniatko , php internals Content-Type: multipart/alternative; boundary="00000000000076b1a405f3ce50d3" Subject: Re: [PHP-DEV] Official Preprocessor From: flaviohbatista@gmail.com (=?UTF-8?Q?Fl=C3=A1vio_Heleno?=) --00000000000076b1a405f3ce50d3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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? --00000000000076b1a405f3ce50d3--