Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119455 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 67903 invoked from network); 2 Feb 2023 22:20:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Feb 2023 22:20:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A3781804AB for ; Thu, 2 Feb 2023 14:20:21 -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,NICE_REPLY_A, 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-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 ; Thu, 2 Feb 2023 14:20:20 -0800 (PST) Received: by mail-wr1-f53.google.com with SMTP id m14so3007729wrg.13 for ; Thu, 02 Feb 2023 14:20:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=HWdPKD6HeH7/S6iZy1Fk06cAH9K1cr6o7cqwhJ3R+PQ=; b=X1kvaUn522XFuYAHRE0vvQWiOLUNmV1IvvjQyy1/H5ZxA7rKQgUBihDM3YZG64rPBu VyMaP3TfUQDvIBU2srctHZo4PdFYPDWumuya+Oep31vh0VJ3muJcWS2jAvFvuGW0eGr1 appktA+pdRlHKlZ6Z2VdhdLH/IZGCtbKqi+gZ18gAKwgKUV2igNi5l9SWrcMrQdJe7Hg nPNEVY9/dk9NFdAPqu9wcdt/yIalNRkfJ9Kr45Xm+JlglqgYoS7h1Y43etpli2MasUU3 hF/+CQIN6n0P/nKGm1lCSKNgNzI17xVd04AE3MP6LbcW5J/Nw6UM0tMpPd9pvwVq0Tqj wrUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HWdPKD6HeH7/S6iZy1Fk06cAH9K1cr6o7cqwhJ3R+PQ=; b=IzfYOWky9ZHRyCXKA3gWhXXY2+D/K6ENHrnURDxV7/yDiMN049TgJO+jhTqN+R9+9/ SKr8iDBtEq2Oanaej5QUZ7Hk6QcvEux/xXlqrxV0n8BM+7zk5eg9t5fxDRrRJbka1m9D fHOmtw1pQ3mC16EYna6m6l469aokmGVXMH9o7M/SdUS1vBrWNZMzliu+7Kci9nDkSevw BwomRYV67eVFoS4qehcK5bIVrVc0Vq9CEhWH+knfG2lAtyUk10I85Fn1YLw1+ojB08RE nv4f76ow6WgUbNLgOKYaGICIyAbLEgUffOiZVcoHHuqFrpUdsej0iIG92vJTZ+f3eLSu lXSQ== X-Gm-Message-State: AO0yUKVPgr5GRPssyb/HqfIOHeu71sXLArfqaA2tmbGfLGSd+YXJJScn YrX2gL2MBe/8DutFfDOoXarNEMPl3hU= X-Google-Smtp-Source: AK7set8i4jELXh21hjq4HsiNJb2TxL1zUb1pYPI28ltQzizUZ+gPdC8b2v3r6R+KfzAPD2OH/yuTWw== X-Received: by 2002:adf:e5c9:0:b0:2bf:ae42:9879 with SMTP id a9-20020adfe5c9000000b002bfae429879mr6713863wrn.32.1675376419420; Thu, 02 Feb 2023 14:20:19 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id c12-20020a5d4ccc000000b002bddac15b3dsm492148wrt.33.2023.02.02.14.20.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Feb 2023 14:20:18 -0800 (PST) Message-ID: <7d0714d0-5ee5-931c-4a76-07f69edc4f1c@gmail.com> Date: Thu, 2 Feb 2023 22:20:18 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Official Preprocessor From: rowan.collins@gmail.com (Rowan Tommins) On 02/02/2023 14:19, someniatko wrote: > 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. This is something I have thought about a lot over the years, and in some ways, it is very appealing; but it does have some problems. One of the biggest is the concept of "type erasure": in a pre-processed or transpiled language, features like Reflection are crippled by not knowing the full information present in the source code. More importantly, dynamic language features - of which PHP has many - also have no access to the type information. That means that a List can sometimes end up with a Cat in it at run-time, because a dynamic call doesn't know that's a problem. I think it's interesting to look around at different approaches to this elsewhere: You mention Python, which I think has probably the *worst* approach: it has official syntax which appears to convey type information, but doesn't actually provide any guarantees if you forget to run an external tool. Outside of that tool, the type information is just another type of comment, just less clearly so than the annotations understood by tools like PhpStan and Psalm in today's PHP. Another approach is TypeScript, which is essentially a complete language in its own right, with JavaScript as a compilation target. As I understand it, you can call JS code from inside a TS project (and vice versa, once the TS is transpiled), but that won't always be seamless, so the two languages will tend to end up with separate ecosystems of libraries and tooling. Implementing a new language also takes time, and ultimately money - in this case, Microsoft's money. A similar project, closer to PHP's heart, is Hack; the main difference being that rather than transpiling to PHP, it initially aimed to compile both languages to a common bytecode, to be executed in a shared VM. However, it turns out that as well as *adding* features on top of PHP, it was necessary for Hack to *remove* features of PHP that weren't compatible with a static typing system, and eventually the interoperability was dropped altogether. It also has money behind it, in this case from Facebook. Dart, which was written completely from scratch (the money this time is Google's), has a type system checked *mostly* at compile-time, but with certain run-time assertions inserted where the compiler can't prove soundness. The approach seems appealing, but PHP would probably end up with a lot of such cases - all the features that the Hack team decided to remove - leading to poor performance and confusing developer experience. I don't have a conclusion to this e-mail, I just thought I'd throw out these thoughts. Regards, -- Rowan Tommins [IMSoP]