Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128389 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id BFEEB1A00BC for ; Mon, 4 Aug 2025 20:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1754340484; bh=JWT4lAj7LChT+ezrXc/oDEaKajdJ9gQM6TdrKJ4Dsqk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EcQBYfRMcy0IkAj3+F9GZyWgagtp6PYFOlpTxkQ/XJpCObCWq0I9+5me76CLPEO9+ E0OgCJMqbPU36oHmpoYuZNEgpDOVTfCXsJxk8rvhDpuiyIBB1FDzXYFEf7+Ncjfgla 1CIEYv37eYtD/wm2RGzWhmVCWkJ/DsK88fHOgmp0cJB1CfgZfkAM+j36lhP+w8izHY qvGyRTbt6ru+5G309Wrcaw4afk6Y2w9NuIyZilYZrD1ExzHwndrANnm7WDLloNJd9o dJzwrpsF4fmg+73YYUZf9aaIWpyGKvHTPdfck0+ISsDAHoikEG2QGvsDI5HEP7332j 2wrKKSyg96Nrw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5BD1B180086 for ; Mon, 4 Aug 2025 20:48:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: *** X-Spam-Status: No, score=3.7 required=5.0 tests=BAYES_50,DMARC_NONE, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 4 Aug 2025 20:48:00 +0000 (UTC) Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-6199e7de142so517831eaf.1 for ; Mon, 04 Aug 2025 13:49:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754340579; x=1754945379; h=content-transfer-encoding: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=FZlIKZkG4+qCvU683PfX7F1OrBj2F49zU5W3XHUf4Uw=; b=BnLONQmNRKFX3BKnyR71TOszXE/KMOmVrhU3MJYU3JpFhXUoZq8/lReusOHHgCwLsW 4iLkznluIs4xrwclKi1zIF2l7xdaz9VgCpBOn2ofTa/VjTzHrgJA72+Wg/L1eAFgGVBx Rj9k+thdfWL8nphSKiwC/3aRsXlswjId9b3cd39ye02ROyD3MOvvR7uRbgZ2aVoXn+Zh V3n7FEHwIcvLZ2CWV3V1w/h0adDIlNRZ1AKbIyk7QscHrkLW6aTF5kX/CaSg9TZZBQF5 q3e+xQhTHnbUZNeCFkDpZaWJkFAmq/UBr/RKwUzmb/aSa9IgibwDb4bTc9FO1ruQBv8m 7gYg== X-Gm-Message-State: AOJu0YyX5qAbQw9MAHV5X8XL132hsjVWyYrUFd/p5QeAH7yzhqSkVmuK fNQ1aqfcXJZH2N653IjtNSnKfhuTRYQcOzUsE7xIVVxYoBqfyZYLH7+Nn7/PHP5AWnO/7jJoQGv SVjG9LuLrJVovHpPrrB+wbKCd4OXLl1xcRoFE X-Gm-Gg: ASbGncsQvfSvbrvDg/tnEtyeBUiH8tR7VW+krWmdBvmpw4FnwTHxodVMn76AECrlheu 2ke7YW4DxYzI+7jmCcprC+k7RkFfJwg+DM/3RR4Kpb3Ut7WxzbSU4JOVdi82UaXKbQhuuPh3i84 nf63qb34EPDBvDKMke/EwE2W6semqhsQWyYkCOUGE0uOFaBS3RUtiKzfFlXbtvLIXP4dicub3Ol 9EPwm0= X-Google-Smtp-Source: AGHT+IFcbUr2Sd9cc+Te0QRgPqKBuYzinS4EpiOvVZN/+JtsyhCfTj9L7CToVqJJEkAdeP0HxS8PeFEikkt73vbJfJE= X-Received: by 2002:a05:6808:2443:b0:41c:95a3:8180 with SMTP id 5614622812f47-433f02ff699mr5934947b6e.20.1754340579560; Mon, 04 Aug 2025 13:49:39 -0700 (PDT) Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 4 Aug 2025 14:49:23 -0600 X-Gm-Features: Ac12FXz0ct52n4_VMmzTG9p-IaP8m8kGo3R7ae_2xpa8GMRxiPL7KUWw3RdJq0Q Message-ID: Subject: Re: [PHP-DEV] Blog post: If we can get partial generics, should we? To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: levim@php.net (Levi Morrison) On Mon, Aug 4, 2025 at 9:26=E2=80=AFAM Larry Garfield wrote: > > Hi folks. I recently wrote a blog post on behalf of the PHP Foundation a= bout some work Gina has been doing regarding generics. It's a follow-up to= last year's post on a similar topic. We are especially looking for feedba= ck from the Internals crew, and voters in particular, on whether or not to = proceed. > > https://thephp.foundation/blog/2025/08/05/compile-generics/ > > Wearing my Internals/voter hat, my stance is a very strong "yes please!" > > -- > Larry Garfield > larry@garfieldtech.com I played with a few iterations of Gina's work. My opinion at that time was that there are too many restrictions to be very useful. Based on those evaluations, I would not consider it to be "80% of the benefit.". With that said, maybe Gina has removed some of the restrictions. Based on the article it , but I'll commit to trying it out again. One thing the article says we're missing and that we we definitely need is unions, or at the very least the union with null. Nullable types are everywhere, and even in your interfaces it's going to show up. For instance, if we had interfaces for Set, Map, etc, there are going to be operations which return nullable values. Sure, exceptions can be thrown in some cases but not all of them. For instance, if you are building a caching data structure, throwing an exceptions on a cache miss would be very bad for performance*. You can separate it into has + get, but this has two lookups which is not desirable for performance. You can return a "tuple" like `[found, $value]` where `$value` may be null, but this loses even more type safety, and isn't a very common pattern in PHP. You really want `T|null`. There are probably other "edges" that are important and should be handled in this first pass, but missing nullable types is not a small thing. * We'll get a mini-optimization in PHP 8.5 for making the exception object faster to construct, but it doesn't speed up the backtrace, which is where most of the performance cost comes from in practice. If you are benchmarking this, make sure to include cases where your stack is a few dozen frames deep. I work for an observability company for my day job, and it is insanely normal for there to be 10+ frames, and still fairly common to be 30+ frames. Think about routing, frameworks, middleware, helper functions, libraries and abstractions, etc. If you use middleware in particular, expect 50+ frames to be normal.