Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121563 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94432 invoked from network); 3 Nov 2023 09:56:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Nov 2023 09:56:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D56AE1804F5 for ; Fri, 3 Nov 2023 02:56:24 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MISSING_HEADERS, 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-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (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 Nov 2023 02:56:14 -0700 (PDT) Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-66d060aa2a4so11063506d6.2 for ; Fri, 03 Nov 2023 02:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699005373; x=1699610173; darn=lists.php.net; h=content-transfer-encoding:cc:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qDp3VM5XlKfKtD+h7czcCyQ4XOnivT1sNybaYY4eR/w=; b=exw9ZFX3QRHa7MIeKIsqErD5WM25pS2pnMPWkHP3O+EylBMm00OSlyuu4UIPpUOhjP /qZYLSXJlz12Sj5Q76oyBQ5breTs/yajMCarxCSAvdhQtNREoa5nwH6SDCbJmkaI3AZn Xok3QUYSH1RcawbPBFxVvzRAGy1qg/DNkvAH30ygr+wndnNAdExmjmR+rSKISgOwuxA+ 2HXpwJqrLYqkV8eNBueWvzzuzw+dtkL05KgFIcEg6mstpKCeAllplC93aGW+i5ToDJ2m gsJgYoC3FIBtc0O6iPwW1bljHAmKQya99z/bg6ranhGGZb8eLF7jLaYUDh6ElhfK1W9S 91qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699005373; x=1699610173; h=content-transfer-encoding:cc: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=qDp3VM5XlKfKtD+h7czcCyQ4XOnivT1sNybaYY4eR/w=; b=EhaKqaKmU1HAVQqjkQe1sdMpCTLvtQ8s6F22jrZAO6RViMeRfLw2E2XeJ0H/MJLmLS FfvLwMsN0CbZLxVq7n1JB4ycXGqkIl/52L6Lze0fyj88mhkvOXEcmhfSLSe4MBagIWsI SoTG8unQa6cnV8jOTlpQ6WmZCzHxh0Kik9P7Ta6yDUNTeEVFS+FegVBLe5bNoYbQf2ra Wumjw5U1/3+ter4Mn4fphrrglM9XiNngyOdxs7uq+E4/ALv7SwUYaaGrihFCW1KRzUc+ iCKmFIgOMpY4jxIlw1tiOySOIrGT2DmUGSeh8528LG6uXrNF/7X3/VuAmSufb4sU+9LE j+uQ== X-Gm-Message-State: AOJu0YxJu43lLl7FIjfP+cSzuib+l21spu5ERGzCMBHN8bFP9g0Wep9c slhLRjm56aUK0cWe0uPCbK2fLfCaW/IhqWWpKwylOotQNiQ= X-Google-Smtp-Source: AGHT+IFm0QHW+ZUk2rOzzpVlz9128bSYDDTTCu3HZKifM+NpaoIenAB5ZYuLHwgTQmH6fA8UO5zb9Yud2X4qPMi8QD4= X-Received: by 2002:a05:6214:d85:b0:66d:33d2:4ff5 with SMTP id e5-20020a0562140d8500b0066d33d24ff5mr25565796qve.41.1699005373410; Fri, 03 Nov 2023 02:56:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 3 Nov 2023 10:56:02 +0100 Message-ID: Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Previous discussions about generics syntax only? From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Daniil On Fri, Nov 3, 2023 at 12:00=E2=80=AFAM wrote: > The much better approach, one that I intend to maybe give a shot at this = Christmas, is to add static analysis functionality to PHP itself (i.e. turn= it into a truly statically typed language). > I have a hunch it may be easy enough to do by hooking into the type infer= ence functionality provided by opcache, and throw compile-time exceptions i= nstead of silently inserting runtime typechecks. The optimizer, including type inference, is limited to the scope of the current file (along with internal functions/classes). Each file is considered a "single compilation unit". When classes from different files reference each other, modifying one file does not require recompiling the other. However, this does mean that we cannot rely on information from other files as they may change at any point. Preloading is the exception, where all preloaded files can assume not to be changed after PHP has booted. We can obviously not limit type checking to preloaded files. We could make type checking a CLI step but how is that really better than PHPStan or Psalm at that point, other than having the official PHP stamp? PHPStan and Psalm are arguably successful *because* they are written in PHP, making them much easier to maintain and contribute to. I'd also like to add that tools like PHPStan and Psalm have much more accurate type representations. PHP does not accurately represent arrays in the optimizer and has no notion of array shapes. The optimizers types are biased towards speed rather than accuracy. Another issue, specifically pertaining to generics, is that PHP has type coercion. In both weak and strict typing mode, a float function parameter will coerce an integer value. However, if generic types are erased at runtime then the VM cannot do coercion for foo($int) (where function foo(T $var)). This will require either accepting inaccurate runtime types, or establishing stricter static rules that do not match the existing behavior. Ilija